Skip to content

Commit

Permalink
Fix bug: call Request->rawContent/getData after Response->end
Browse files Browse the repository at this point in the history
  • Loading branch information
twose committed Jul 26, 2019
1 parent 3f42d91 commit b989ba9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions swoole_http_server.cc
Expand Up @@ -218,6 +218,7 @@ void swoole_http_server_init_context(swServer *serv, http_context *ctx)

void swoole_http_context_free(http_context *ctx)
{
swoole_set_object(ctx->request.zobject, NULL);
swoole_set_object(ctx->response.zobject, NULL);
http_request *req = &ctx->request;
http_response *res = &ctx->response;
Expand Down
40 changes: 40 additions & 0 deletions tests/swoole_http_server/bug_get_request_data_after_end.phpt
@@ -0,0 +1,40 @@
--TEST--
swoole_http_server: bug get request data after response end
--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) {
echo httpGetBody("http://127.0.0.1:{$pm->getFreePort()}/", ['data' => $pm->getRandomData()]) . PHP_EOL;
});
$pm->kill();
};
$pm->childFunc = function () use ($pm) {
$http = new Swoole\Http\Server('127.0.0.1', $pm->getFreePort(), SWOOLE_BASE);
$http->set(['log_file' => '/dev/null']);
$http->on('workerStart', function () use ($pm) {
$pm->wakeup();
});
$http->on("request", function (Swoole\Http\Request $request, Swoole\Http\Response $response) {
$response->end('OK');
switch_process();
var_dump($request->rawContent());
var_dump($request->getData());
});
$http->start();
};
$pm->childFirst();
$pm->run();
?>
--EXPECTF--
OK

Warning: Swoole\Http\Request::rawContent(): %s in %s on line %d
bool(false)

Warning: Swoole\Http\Request::getData(): %s in %s on line %d
bool(false)

0 comments on commit b989ba9

Please sign in to comment.