PHP: improved response status code handling.
There's no reason to parse "http_status_line"; the PHP interpreter already does this. If the line contains a valid status code, it's assigned to "http_response_code". This also fixes invalid status line handling, where the nxt_int_parse() function returned -1; it was cast to unsigned, yielding response code 65535.
This commit is contained in:
@@ -730,7 +730,7 @@ static int
|
|||||||
nxt_php_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
|
nxt_php_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
|
||||||
{
|
{
|
||||||
int rc, fields_count;
|
int rc, fields_count;
|
||||||
char *colon, *status_line, *value;
|
char *colon, *value;
|
||||||
uint16_t status;
|
uint16_t status;
|
||||||
uint32_t resp_size;
|
uint32_t resp_size;
|
||||||
nxt_php_run_ctx_t *ctx;
|
nxt_php_run_ctx_t *ctx;
|
||||||
@@ -762,17 +762,7 @@ nxt_php_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
|
|||||||
resp_size += h->header_len;
|
resp_size += h->header_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SG(sapi_headers).http_status_line) {
|
status = SG(sapi_headers).http_response_code;
|
||||||
status_line = SG(sapi_headers).http_status_line;
|
|
||||||
|
|
||||||
status = nxt_int_parse((u_char *) status_line + 9, 3);
|
|
||||||
|
|
||||||
} else if (SG(sapi_headers).http_response_code) {
|
|
||||||
status = SG(sapi_headers).http_response_code;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
status = 200;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = nxt_unit_response_init(req, status, fields_count, resp_size);
|
rc = nxt_unit_response_init(req, status, fields_count, resp_size);
|
||||||
if (nxt_slow_path(rc != NXT_UNIT_OK)) {
|
if (nxt_slow_path(rc != NXT_UNIT_OK)) {
|
||||||
|
|||||||
4
test/php/header/index.php
Normal file
4
test/php/header/index.php
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?php
|
||||||
|
header($_SERVER['HTTP_X_HEADER']);
|
||||||
|
header('Content-Length: 0');
|
||||||
|
?>
|
||||||
@@ -102,6 +102,46 @@ class TestPHPApplication(TestApplicationPHP):
|
|||||||
self.assertEqual(resp['status'], 200, 'status')
|
self.assertEqual(resp['status'], 200, 'status')
|
||||||
self.assertNotEqual(resp['body'], '', 'body not empty')
|
self.assertNotEqual(resp['body'], '', 'body not empty')
|
||||||
|
|
||||||
|
def test_php_application_header_status(self):
|
||||||
|
self.load('header')
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
self.get(
|
||||||
|
headers={
|
||||||
|
'Host': 'localhost',
|
||||||
|
'Connection': 'close',
|
||||||
|
'X-Header': 'HTTP/1.1 404 Not Found',
|
||||||
|
}
|
||||||
|
)['status'],
|
||||||
|
404,
|
||||||
|
'status',
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
self.get(
|
||||||
|
headers={
|
||||||
|
'Host': 'localhost',
|
||||||
|
'Connection': 'close',
|
||||||
|
'X-Header': 'http/1.1 404 Not Found',
|
||||||
|
}
|
||||||
|
)['status'],
|
||||||
|
404,
|
||||||
|
'status case insensitive',
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
self.get(
|
||||||
|
headers={
|
||||||
|
'Host': 'localhost',
|
||||||
|
'Connection': 'close',
|
||||||
|
'X-Header': 'HTTP/ 404 Not Found',
|
||||||
|
}
|
||||||
|
)['status'],
|
||||||
|
404,
|
||||||
|
'status version empty',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_php_application_404(self):
|
def test_php_application_404(self):
|
||||||
self.load('404')
|
self.load('404')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user