diff options
author | Valentin Bartenev <vbart@nginx.com> | 2019-07-05 18:42:30 +0300 |
---|---|---|
committer | Valentin Bartenev <vbart@nginx.com> | 2019-07-05 18:42:30 +0300 |
commit | 924165c90ba51dd4ffea2c45541d46af56352d73 (patch) | |
tree | 2e0287393a13e2c0fc162585d73f72eea7fb8332 | |
parent | e1de5bcfabf468b88b42aa27c60a643e97aacc11 (diff) | |
download | unit-924165c90ba51dd4ffea2c45541d46af56352d73.tar.gz unit-924165c90ba51dd4ffea2c45541d46af56352d73.tar.bz2 |
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.
Diffstat (limited to '')
-rw-r--r-- | src/nxt_php_sapi.c | 14 | ||||
-rw-r--r-- | test/php/header/index.php | 4 | ||||
-rw-r--r-- | test/test_php_application.py | 40 |
3 files changed, 46 insertions, 12 deletions
diff --git a/src/nxt_php_sapi.c b/src/nxt_php_sapi.c index df7cf243..dfad9eb8 100644 --- a/src/nxt_php_sapi.c +++ b/src/nxt_php_sapi.c @@ -730,7 +730,7 @@ static int nxt_php_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) { int rc, fields_count; - char *colon, *status_line, *value; + char *colon, *value; uint16_t status; uint32_t resp_size; 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; } - if (SG(sapi_headers).http_status_line) { - 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; - } + status = SG(sapi_headers).http_response_code; rc = nxt_unit_response_init(req, status, fields_count, resp_size); if (nxt_slow_path(rc != NXT_UNIT_OK)) { diff --git a/test/php/header/index.php b/test/php/header/index.php new file mode 100644 index 00000000..1aa5ca04 --- /dev/null +++ b/test/php/header/index.php @@ -0,0 +1,4 @@ +<?php +header($_SERVER['HTTP_X_HEADER']); +header('Content-Length: 0'); +?> diff --git a/test/test_php_application.py b/test/test_php_application.py index 8032e96e..bf0d3bd1 100644 --- a/test/test_php_application.py +++ b/test/test_php_application.py @@ -102,6 +102,46 @@ class TestPHPApplication(TestApplicationPHP): self.assertEqual(resp['status'], 200, 'status') 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): self.load('404') |