Skip to content

Commit 66fcc35

Browse files
committed
fix Http\Response::end() bad return value
1 parent 6d8b573 commit 66fcc35

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

ext-src/swoole_http_server.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,8 @@ bool http_context_send_data(http_context *ctx, const char *data, size_t length)
291291
ZVAL_STRINGL(&yield_data, data, length);
292292
php_swoole_server_send_yield(serv, ctx->fd, &yield_data, &return_value);
293293
return Z_BVAL_P(&return_value);
294-
} else {
295-
return true;
296294
}
295+
return retval;
297296
}
298297

299298
static bool http_context_sendfile(http_context *ctx, const char *file, uint32_t l_file, off_t offset, size_t length) {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
--TEST--
2+
swoole_http_server: http_compression
3+
--SKIPIF--
4+
<?php require __DIR__ . '/../include/skipif.inc'; ?>
5+
--FILE--
6+
<?php
7+
require __DIR__ . '/../include/bootstrap.php';
8+
9+
$pm = new ProcessManager;
10+
$pm->parentFunc = function () use ($pm)
11+
{
12+
go(function () use ($pm) {
13+
try {
14+
$data = httpGetBody("http://127.0.0.1:{$pm->getFreePort()}/");
15+
} catch(Exception $e) {
16+
Assert::contains($e->getMessage(), 'Connection reset by peer');
17+
}
18+
$pm->kill();
19+
});
20+
Swoole\Event::wait();
21+
echo "DONE\n";
22+
};
23+
24+
$pm->childFunc = function () use ($pm)
25+
{
26+
$http = new swoole_http_server('127.0.0.1', $pm->getFreePort());
27+
28+
$http->set([
29+
'http_compression' => false,
30+
'log_file' => '/dev/null',
31+
'buffer_output_size' => 128 * 1024,
32+
]);
33+
34+
$http->on("WorkerStart", function ($serv, $wid) use ($pm) {
35+
$pm->wakeup();
36+
});
37+
38+
$http->on("request", function ($request, swoole_http_response $response) {
39+
Assert::eq($response->end(str_repeat('A', 256 * 1024)), false);
40+
Assert::eq(swoole_last_error(), SWOOLE_ERROR_DATA_LENGTH_TOO_LARGE);
41+
});
42+
43+
$http->start();
44+
};
45+
46+
$pm->childFirst();
47+
$pm->run();
48+
?>
49+
--EXPECT--
50+
DONE

0 commit comments

Comments
 (0)