Skip to content

Commit

Permalink
[coro_http_client]fix reset (#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos authored Dec 4, 2024
1 parent c902933 commit 73577fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion include/ylt/standalone/cinatra/coro_http_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,9 @@ class coro_http_client : public std::enable_shared_from_this<coro_http_client> {
bool is_body_in_out_buf() const { return !out_buf_.empty(); }

void reset() {
if (!has_closed())
if (!has_closed()) {
close_socket(*socket_);
}

socket_->impl_ = asio::ip::tcp::socket{executor_wrapper_.context()};
if (!socket_->impl_.is_open()) {
Expand All @@ -689,6 +690,7 @@ class coro_http_client : public std::enable_shared_from_this<coro_http_client> {
socket_->ssl_stream_ =
std::make_unique<asio::ssl::stream<asio::ip::tcp::socket &>>(
socket_->impl_, *ssl_ctx_);
has_init_ssl_ = false;
}
#endif
#ifdef BENCHMARK_TEST
Expand Down
11 changes: 10 additions & 1 deletion src/coro_http/tests/test_cinatra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,16 @@ TEST_CASE("test ssl client") {
auto result = client.get("https://www.bing.com");
CHECK(result.status >= 200);
}

{
coro_http_client client{};
auto ret = client.get("https://baidu.com");
client.reset();
ret = client.get("http://cn.bing.com");
std::cout << ret.status << std::endl;
client.reset();
ret = client.get("https://baidu.com");
std::cout << ret.status << std::endl;
}
{
coro_http_client client{};
auto r =
Expand Down

0 comments on commit 73577fe

Please sign in to comment.