diff --git a/include/cinatra/coro_http_client.hpp b/include/cinatra/coro_http_client.hpp index c22391bf..a9304415 100644 --- a/include/cinatra/coro_http_client.hpp +++ b/include/cinatra/coro_http_client.hpp @@ -400,9 +400,8 @@ class coro_http_client : public std::enable_shared_from_this { async_simple::coro::Lazy write_ws_frame(std::span msg, websocket ws, opcode op, resp_data &data, - bool eof = true, - bool need_compression = false) { - auto header = ws.encode_frame(msg, op, eof, need_compression); + bool eof = true) { + auto header = ws.encode_frame(msg, op, eof, enable_ws_deflate_); std::vector buffers{ asio::buffer(header), asio::buffer(msg.data(), msg.size())}; @@ -446,27 +445,27 @@ class coro_http_client : public std::enable_shared_from_this { std::span span{}; if constexpr (is_span_v) { - bool need_compress = false; span = {source.data(), source.size()}; #ifdef CINATRA_ENABLE_GZIP std::string dest_buf; - gzip_compress({source.data(), source.size()}, dest_buf, span, data); - need_compress = true; + if (enable_ws_deflate_) { + gzip_compress({source.data(), source.size()}, dest_buf, span, data); + } #endif - co_await write_ws_frame(span, ws, op, data, true, need_compress); + co_await write_ws_frame(span, ws, op, data, true); } else { while (true) { auto result = co_await source(); - bool need_compress = false; span = {result.buf.data(), result.buf.size()}; #ifdef CINATRA_ENABLE_GZIP std::string dest_buf; - gzip_compress({result.buf.data(), result.buf.size()}, dest_buf, span, - data); - need_compress = true; + if (enable_ws_deflate_) { + gzip_compress({result.buf.data(), result.buf.size()}, dest_buf, span, + data); + } #endif - co_await write_ws_frame(span, ws, op, data, result.eof, need_compress); + co_await write_ws_frame(span, ws, op, data, result.eof); if (result.eof || data.status == 404) { break; @@ -2402,8 +2401,8 @@ class coro_http_client : public std::enable_shared_from_this { bool should_reset_ = false; config config_; -#ifdef CINATRA_ENABLE_GZIP bool enable_ws_deflate_ = false; +#ifdef CINATRA_ENABLE_GZIP bool is_server_support_ws_deflate_ = false; std::string inflate_str_; #endif diff --git a/tests/test_cinatra.cpp b/tests/test_cinatra.cpp index 905653fb..be8c85b0 100644 --- a/tests/test_cinatra.cpp +++ b/tests/test_cinatra.cpp @@ -1055,6 +1055,8 @@ async_simple::coro::Lazy test_collect_all() { std::vector> futures; for (int i = 0; i < 2; ++i) { auto client = std::make_shared(); + client->set_conn_timeout(3s); + client->set_req_timeout(5s); v.push_back(client); futures.push_back(client->async_get("http://www.baidu.com/")); } @@ -1167,6 +1169,8 @@ TEST_CASE("test request with out buffer") { { detail::resize(str, 1024 * 64); coro_http_client client; + client.set_conn_timeout(3s); + client.set_req_timeout(5s); std::string dest = "http://www.baidu.com"; auto ret = client.async_request(dest, http_method::GET, req_context<>{}, {}, std::span{str.data(), str.size()});