Skip to content

Commit dc1377e

Browse files
authored
Added http_compression/body_decompression options for HttpClient (swoole#4299)
1 parent 76202bd commit dc1377e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

ext-src/swoole_http_client_coro.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ class HttpClient {
117117
bool websocket = false; // if upgrade successfully
118118
bool chunked = false; // Transfer-Encoding: chunked
119119
bool websocket_mask = true; // enable websocket mask
120+
bool body_decompression = true;
121+
bool http_compression = true;
120122
#ifdef SW_HAVE_ZLIB
121123
bool websocket_compression = false; // allow to compress websocket messages
122124
#endif
@@ -541,7 +543,7 @@ static int http_parser_on_headers_complete(swoole_http_parser *parser) {
541543
static int http_parser_on_body(swoole_http_parser *parser, const char *at, size_t length) {
542544
HttpClient *http = (HttpClient *) parser->data;
543545
#ifdef SW_HAVE_COMPRESSION
544-
if (!http->compression_error && http->compress_method != HTTP_COMPRESS_NONE) {
546+
if (http->body_decompression && !http->compression_error && http->compress_method != HTTP_COMPRESS_NONE) {
545547
if (!http->decompress_response(at, length)) {
546548
http->compression_error = true;
547549
goto _append_raw;
@@ -774,6 +776,12 @@ void HttpClient::apply_setting(zval *zset, const bool check_all) {
774776
if (php_swoole_array_get_value(vht, "websocket_mask", ztmp)) {
775777
websocket_mask = zval_is_true(ztmp);
776778
}
779+
if (php_swoole_array_get_value(vht, "http_compression", ztmp)) {
780+
http_compression = zval_is_true(ztmp);
781+
}
782+
if (php_swoole_array_get_value(vht, "body_decompression", ztmp)) {
783+
body_decompression = zval_is_true(ztmp);
784+
}
777785
#ifdef SW_HAVE_ZLIB
778786
if (php_swoole_array_get_value(vht, "websocket_compression", ztmp)) {
779787
websocket_compression = zval_is_true(ztmp);
@@ -1060,7 +1068,7 @@ bool HttpClient::send() {
10601068
}
10611069
}
10621070
#ifdef SW_HAVE_COMPRESSION
1063-
if (!(header_flag & HTTP_HEADER_ACCEPT_ENCODING)) {
1071+
if (http_compression && !(header_flag & HTTP_HEADER_ACCEPT_ENCODING)) {
10641072
add_headers(buffer,
10651073
ZEND_STRL("Accept-Encoding"),
10661074
#if defined(SW_HAVE_ZLIB) && defined(SW_HAVE_BROTLI)

0 commit comments

Comments
 (0)