Skip to content

Commit

Permalink
fix Http\Response::end() bad return value
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed May 14, 2021
1 parent 6d8b573 commit 66fcc35
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
3 changes: 1 addition & 2 deletions ext-src/swoole_http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,8 @@ bool http_context_send_data(http_context *ctx, const char *data, size_t length)
ZVAL_STRINGL(&yield_data, data, length);
php_swoole_server_send_yield(serv, ctx->fd, &yield_data, &return_value);
return Z_BVAL_P(&return_value);
} else {
return true;
}
return retval;
}

static bool http_context_sendfile(http_context *ctx, const char *file, uint32_t l_file, off_t offset, size_t length) {
Expand Down
50 changes: 50 additions & 0 deletions tests/swoole_http_server/error_1203.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
--TEST--
swoole_http_server: http_compression
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';

$pm = new ProcessManager;
$pm->parentFunc = function () use ($pm)
{
go(function () use ($pm) {
try {
$data = httpGetBody("http://127.0.0.1:{$pm->getFreePort()}/");
} catch(Exception $e) {
Assert::contains($e->getMessage(), 'Connection reset by peer');
}
$pm->kill();
});
Swoole\Event::wait();
echo "DONE\n";
};

$pm->childFunc = function () use ($pm)
{
$http = new swoole_http_server('127.0.0.1', $pm->getFreePort());

$http->set([
'http_compression' => false,
'log_file' => '/dev/null',
'buffer_output_size' => 128 * 1024,
]);

$http->on("WorkerStart", function ($serv, $wid) use ($pm) {
$pm->wakeup();
});

$http->on("request", function ($request, swoole_http_response $response) {
Assert::eq($response->end(str_repeat('A', 256 * 1024)), false);
Assert::eq(swoole_last_error(), SWOOLE_ERROR_DATA_LENGTH_TOO_LARGE);
});

$http->start();
};

$pm->childFirst();
$pm->run();
?>
--EXPECT--
DONE

0 comments on commit 66fcc35

Please sign in to comment.