Skip to content

Commit

Permalink
set_ws_deflate
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Apr 19, 2024
1 parent 3819115 commit e001f60
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 8 additions & 5 deletions include/cinatra/coro_http_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,18 +276,21 @@ class coro_http_client : public std::enable_shared_from_this<coro_http_client> {
return std::move(body_);
}

#ifdef CINATRA_ENABLE_GZIP
void set_ws_deflate(bool enable_ws_deflate) {
enable_ws_deflate_ = enable_ws_deflate;
}
#endif

// only make socket connet(or handshake) to the host
async_simple::coro::Lazy<resp_data> connect(std::string uri,
bool enable_ws_deflate = false) {
async_simple::coro::Lazy<resp_data> connect(std::string uri) {
resp_data data{};
bool no_schema = !has_schema(uri);
std::string append_uri;
if (no_schema) {
append_uri.append("http://").append(uri);
}

enable_ws_deflate_ = enable_ws_deflate;

auto [ok, u] = handle_uri(data, no_schema ? append_uri : uri);
if (!ok) {
co_return resp_data{std::make_error_code(std::errc::protocol_error), 404};
Expand Down Expand Up @@ -2123,8 +2126,8 @@ class coro_http_client : public std::enable_shared_from_this<coro_http_client> {
std::string resp_chunk_str_;
std::span<char> out_buf_;

bool enable_ws_deflate_ = false;
#ifdef CINATRA_ENABLE_GZIP
bool enable_ws_deflate_ = false;
bool is_server_support_ws_deflate_ = false;
std::string inflate_str_;
#endif
Expand Down
3 changes: 2 additions & 1 deletion tests/test_cinatra_websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,9 @@ TEST_CASE("test websocket permessage defalte") {
std::this_thread::sleep_for(std::chrono::milliseconds(300));

coro_http_client client{};
client.set_ws_deflate(true);
async_simple::coro::syncAwait(
client.connect("ws://localhost:8090/ws_extesion", true));
client.connect("ws://localhost:8090/ws_extesion"));

std::string send_str("test");

Expand Down

0 comments on commit e001f60

Please sign in to comment.