Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added http_compression/body_decompression options for HttpClient #4299

Merged
merged 1 commit into from
Jul 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions ext-src/swoole_http_client_coro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class HttpClient {
bool websocket = false; // if upgrade successfully
bool chunked = false; // Transfer-Encoding: chunked
bool websocket_mask = true; // enable websocket mask
bool body_decompression = true;
bool http_compression = true;
#ifdef SW_HAVE_ZLIB
bool websocket_compression = false; // allow to compress websocket messages
#endif
Expand Down Expand Up @@ -541,7 +543,7 @@ static int http_parser_on_headers_complete(swoole_http_parser *parser) {
static int http_parser_on_body(swoole_http_parser *parser, const char *at, size_t length) {
HttpClient *http = (HttpClient *) parser->data;
#ifdef SW_HAVE_COMPRESSION
if (!http->compression_error && http->compress_method != HTTP_COMPRESS_NONE) {
if (http->body_decompression && !http->compression_error && http->compress_method != HTTP_COMPRESS_NONE) {
if (!http->decompress_response(at, length)) {
http->compression_error = true;
goto _append_raw;
Expand Down Expand Up @@ -774,6 +776,12 @@ void HttpClient::apply_setting(zval *zset, const bool check_all) {
if (php_swoole_array_get_value(vht, "websocket_mask", ztmp)) {
websocket_mask = zval_is_true(ztmp);
}
if (php_swoole_array_get_value(vht, "http_compression", ztmp)) {
http_compression = zval_is_true(ztmp);
}
if (php_swoole_array_get_value(vht, "body_decompression", ztmp)) {
body_decompression = zval_is_true(ztmp);
}
#ifdef SW_HAVE_ZLIB
if (php_swoole_array_get_value(vht, "websocket_compression", ztmp)) {
websocket_compression = zval_is_true(ztmp);
Expand Down Expand Up @@ -1060,7 +1068,7 @@ bool HttpClient::send() {
}
}
#ifdef SW_HAVE_COMPRESSION
if (!(header_flag & HTTP_HEADER_ACCEPT_ENCODING)) {
if (http_compression && !(header_flag & HTTP_HEADER_ACCEPT_ENCODING)) {
add_headers(buffer,
ZEND_STRL("Accept-Encoding"),
#if defined(SW_HAVE_ZLIB) && defined(SW_HAVE_BROTLI)
Expand Down