From 2820b693a590f9000e410d7a3a5a4301749786db Mon Sep 17 00:00:00 2001 From: NathanFreeman <1056159381@qq.com> Date: Thu, 27 Jul 2023 00:00:54 +0800 Subject: [PATCH 1/2] Fix bug #5107 --- ext-src/swoole_http_response.cc | 2 +- tests/swoole_http_server/bug_5107.phpt | 55 ++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tests/swoole_http_server/bug_5107.phpt diff --git a/ext-src/swoole_http_response.cc b/ext-src/swoole_http_response.cc index 676cc04203b..0928ed22fda 100644 --- a/ext-src/swoole_http_response.cc +++ b/ext-src/swoole_http_response.cc @@ -397,7 +397,7 @@ void HttpContext::build_header(String *http_buffer, const char *body, size_t len http_buffer->append(ZEND_STRL("HTTP/1.1 ")); http_buffer->append(response.status); http_buffer->append(ZEND_STRL(" ")); - http_buffer->append(ZEND_STRL(response.reason)); + http_buffer->append(response.reason, strlen(response.reason)); http_buffer->append(ZEND_STRL("\r\n")); } diff --git a/tests/swoole_http_server/bug_5107.phpt b/tests/swoole_http_server/bug_5107.phpt new file mode 100644 index 00000000000..e571c3b2d55 --- /dev/null +++ b/tests/swoole_http_server/bug_5107.phpt @@ -0,0 +1,55 @@ +--TEST-- +swoole_http_server: bug Github#5107 Error response status +--SKIPIF-- + +--FILE-- +initRandomData(1); +$pm->parentFunc = function () use ($pm) { + Co\run(function () use ($pm) { + + // without special content-length + $headers = httpGetHeaders( + "http://127.0.0.1:{$pm->getFreePort()}?encoding=1", + [ + 'headers' => ['Accept-Encoding' => 'gzip, br'], + ] + ); + var_dump($headers); + }); + + $pm->kill(); + echo "DONE\n"; +}; + +$pm->childFunc = function () use ($pm) { + $http = new Swoole\Http\Server('127.0.0.1', $pm->getFreePort(), SWOOLE_BASE); + $http->on('workerStart', function () use ($pm) { + $pm->wakeup(); + }); + $http->on('request', function (Swoole\Http\Request $request, Swoole\Http\Response $response) use ($pm) { + $response->status(200, "status"); + $response->end("Hello World"); + }); + $http->start(); +}; +$pm->childFirst(); +$pm->run(); +?> +--EXPECTF-- +array(5) { + ["server"]=> + string(18) "swoole-http-server" + ["date"]=> + string(%d) %s + ["connection"]=> + string(10) "keep-alive" + ["content-type"]=> + string(9) "text/html" + ["content-length"]=> + string(2) "11" +} +DONE From dd8dc6dd5f81b985c920f254a8fb943b698fee8c Mon Sep 17 00:00:00 2001 From: NathanFreeman <1056159381@qq.com> Date: Thu, 27 Jul 2023 00:07:32 +0800 Subject: [PATCH 2/2] test --- tests/swoole_http_server/bug_5107.phpt | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/swoole_http_server/bug_5107.phpt b/tests/swoole_http_server/bug_5107.phpt index e571c3b2d55..5e071f96071 100644 --- a/tests/swoole_http_server/bug_5107.phpt +++ b/tests/swoole_http_server/bug_5107.phpt @@ -10,14 +10,7 @@ $pm = new ProcessManager; $pm->initRandomData(1); $pm->parentFunc = function () use ($pm) { Co\run(function () use ($pm) { - - // without special content-length - $headers = httpGetHeaders( - "http://127.0.0.1:{$pm->getFreePort()}?encoding=1", - [ - 'headers' => ['Accept-Encoding' => 'gzip, br'], - ] - ); + $headers = httpGetHeaders("http://127.0.0.1:{$pm->getFreePort()}"); var_dump($headers); });