From 5dfb7f296be471c20c21b3e39c00412e81706d78 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Thu, 6 Nov 2014 16:22:18 +0100 Subject: [PATCH] Fixed bug #66891 (Unexpected HTTP 401 after NTLM authentication) 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 | 1 + php_http_env_response.c | 22 +++++++++++----------- tests/bug66891.phpt | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 tests/bug66891.phpt diff --git a/package.xml b/package.xml index 1966888..3e73111 100644 --- a/package.xml +++ b/package.xml @@ -50,6 +50,7 @@ v2: http://dev.iworks.at/ext-http/lcov/ext/http/ diff --git a/php_http_env_response.c b/php_http_env_response.c index c155dde..13a35c6 100644 --- a/php_http_env_response.c +++ b/php_http_env_response.c @@ -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 index 0000000..0fd84f8 --- /dev/null +++ b/tests/bug66891.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #66891 (Unexpected HTTP 401 after NTLM authentication) +--SKIPIF-- + +--GET-- +dummy=1 +--FILE-- +setResponseCode(200); +$r->send(); +var_dump(http_response_code()); +?> +--EXPECT-- +int(200) \ No newline at end of file -- 2.30.2