Skip to content

Commit

Permalink
Fix bug #5107 (#5108)
Browse files Browse the repository at this point in the history
* Fix bug #5107

* test
  • Loading branch information
NathanFreeman committed Jul 28, 2023
1 parent db71b11 commit 08c6c05
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext-src/swoole_http_response.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

Expand Down
48 changes: 48 additions & 0 deletions tests/swoole_http_server/bug_5107.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--TEST--
swoole_http_server: bug Github#5107 Error response status
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';

$pm = new ProcessManager;
$pm->initRandomData(1);
$pm->parentFunc = function () use ($pm) {
Co\run(function () use ($pm) {
$headers = httpGetHeaders("http://127.0.0.1:{$pm->getFreePort()}");
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

0 comments on commit 08c6c05

Please sign in to comment.