Skip to content

Commit

Permalink
Added http_compression/body_decompression options for HttpClient (#4299)
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf authored Jul 5, 2021
1 parent 76202bd commit dc1377e
Showing 1 changed file with 10 additions and 2 deletions.
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

0 comments on commit dc1377e

Please sign in to comment.