Fixed bug #66891 (Unexpected HTTP 401 after NTLM authentication)
authorMichael Wallner <mike@php.net>
Thu, 6 Nov 2014 15:22:18 +0000 (16:22 +0100)
committerMichael Wallner <mike@php.net>
Thu, 6 Nov 2014 15:22:18 +0000 (16:22 +0100)
If you set a "WWW-Authenticate" header PHP automatically issues a 401.

http\Env\Response slurps any set headers and re-sends it after sending
the status code, so that PHP might be resetting the status code to 401
because it sees again an WWW-Authenticate header.

Send the status code after any headers to avoid this issue.

package.xml
php_http_env_response.c
tests/bug66891.phpt [new file with mode: 0644]

index 1966888..3e73111 100644 (file)
@@ -50,6 +50,7 @@ v2: http://dev.iworks.at/ext-http/lcov/ext/http/
  <notes><![CDATA[
 * Fixed bug #68353 (QsoSSL support removed in libcurl 7.39)
 * Fixed bug #68149 (duplicate content-length with libcurl < 7.23)
+* Fixed bug #66891 (Unexpected HTTP 401 after NTLM authentication)
 ]]></notes>
  <contents>
   <dir name="/">
index c155dde..13a35c6 100644 (file)
@@ -329,6 +329,17 @@ static STATUS php_http_env_response_send_head(php_http_env_response_t *r, php_ht
                return ret;
        }
 
+       if ((zoption = get_option(options, ZEND_STRL("headers") TSRMLS_CC))) {
+               if (Z_TYPE_P(zoption) == IS_ARRAY) {
+                       php_http_header_to_callback(Z_ARRVAL_P(zoption), 0, (php_http_pass_format_callback_t) r->ops->set_header, r TSRMLS_CC);
+               }
+               zval_ptr_dtor(&zoption);
+       }
+
+       if (ret != SUCCESS) {
+               return ret;
+       }
+
        if ((zoption = get_option(options, ZEND_STRL("responseCode") TSRMLS_CC))) {
                zval *zoption_copy = php_http_ztyp(IS_LONG, zoption);
 
@@ -359,17 +370,6 @@ static STATUS php_http_env_response_send_head(php_http_env_response_t *r, php_ht
                return ret;
        }
 
-       if ((zoption = get_option(options, ZEND_STRL("headers") TSRMLS_CC))) {
-               if (Z_TYPE_P(zoption) == IS_ARRAY) {
-                       php_http_header_to_callback(Z_ARRVAL_P(zoption), 0, (php_http_pass_format_callback_t) r->ops->set_header, r TSRMLS_CC);
-               }
-               zval_ptr_dtor(&zoption);
-       }
-
-       if (ret != SUCCESS) {
-               return ret;
-       }
-
        if ((zoption = get_option(options, ZEND_STRL("contentType") TSRMLS_CC))) {
                zval *zoption_copy = php_http_ztyp(IS_STRING, zoption);
 
diff --git a/tests/bug66891.phpt b/tests/bug66891.phpt
new file mode 100644 (file)
index 0000000..0fd84f8
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Bug #66891 (Unexpected HTTP 401 after NTLM authentication)
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--GET--
+dummy=1
+--FILE--
+<?php
+header("WWW-Authenticate: none");
+$r = new http\Env\Response;
+$r->setResponseCode(200);
+$r->send();
+var_dump(http_response_code());
+?>
+--EXPECT--
+int(200)
\ No newline at end of file