Skip to content

Commit

Permalink
[5.1]Fix send chunk error (#5567)
Browse files Browse the repository at this point in the history
* fix send chunk error

* Update chunk.phpt

---------

Co-authored-by: Tianfeng.Han <[email protected]>
  • Loading branch information
NathanFreeman and matyhtf authored Nov 20, 2024
1 parent ae12f42 commit 8d44c7e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
4 changes: 0 additions & 4 deletions ext-src/swoole_http_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -845,10 +845,6 @@ const char *HttpContext::get_content_encoding() {
}
#endif

static void swoole_request_read_fd_property(zend_object *object, HttpContext *ctx) {
zend_update_property_long(swoole_http_request_ce, object, ZEND_STRL("fd"), ctx->fd);
}

static PHP_METHOD(swoole_http_request, getContent) {
HttpContext *ctx = php_swoole_http_request_get_and_check_context(ZEND_THIS);
if (UNEXPECTED(!ctx)) {
Expand Down
5 changes: 3 additions & 2 deletions ext-src/swoole_http_response.cc
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ bool HttpContext::send_file(const char *file, uint32_t l_file, off_t offset, siz
void HttpContext::end(zval *zdata, zval *return_value) {
char *data = nullptr;
size_t length = zdata ? php_swoole_get_send_data(zdata, &data) : 0;
String *http_buffer = nullptr;

if (send_chunked) {
if (send_trailer_) {
Expand All @@ -760,7 +761,7 @@ void HttpContext::end(zval *zdata, zval *return_value) {
}
}
send_chunked = 0;
return;
goto _skip_copy;
}

#ifdef SW_HAVE_ZLIB
Expand Down Expand Up @@ -790,7 +791,7 @@ void HttpContext::end(zval *zdata, zval *return_value) {
}
#endif

String *http_buffer = get_write_buffer();
http_buffer = get_write_buffer();
http_buffer->clear();
build_header(http_buffer, data, length);

Expand Down
4 changes: 2 additions & 2 deletions tests/swoole_http_server/chunk.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ $pm->childFunc = function () use ($pm) {
$http->on("request", function (Swoole\Http\Request $request, Swoole\Http\Response $response) {
$data = str_split(file_get_contents(TEST_IMAGE), 8192);
foreach ($data as $chunk) {
$response->write($chunk);
Assert::true($response->write($chunk));
}
$response->end();
Assert::true($response->end());
});

$http->start();
Expand Down
6 changes: 3 additions & 3 deletions tests/swoole_http_server/trailer.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ $pm->childFunc = function () use ($pm) {
$http->on('request', function (Swoole\Http\Request $request, Swoole\Http\Response $response) {
$response->header('trailer', 'Content-MD5');
$data = 'hello world';
$response->write($data);
$response->trailer('Content-MD5', md5($data));
$response->end();
Assert::true($response->write($data));
Assert::true($response->trailer('Content-MD5', md5($data)));
Assert::true($response->end());
});
$http->start();
};
Expand Down

0 comments on commit 8d44c7e

Please sign in to comment.