Skip to content

Commit 73577fe

Browse files
authored
[coro_http_client]fix reset (#840)
1 parent c902933 commit 73577fe

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

include/ylt/standalone/cinatra/coro_http_client.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,9 @@ class coro_http_client : public std::enable_shared_from_this<coro_http_client> {
667667
bool is_body_in_out_buf() const { return !out_buf_.empty(); }
668668

669669
void reset() {
670-
if (!has_closed())
670+
if (!has_closed()) {
671671
close_socket(*socket_);
672+
}
672673

673674
socket_->impl_ = asio::ip::tcp::socket{executor_wrapper_.context()};
674675
if (!socket_->impl_.is_open()) {
@@ -689,6 +690,7 @@ class coro_http_client : public std::enable_shared_from_this<coro_http_client> {
689690
socket_->ssl_stream_ =
690691
std::make_unique<asio::ssl::stream<asio::ip::tcp::socket &>>(
691692
socket_->impl_, *ssl_ctx_);
693+
has_init_ssl_ = false;
692694
}
693695
#endif
694696
#ifdef BENCHMARK_TEST

src/coro_http/tests/test_cinatra.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,16 @@ TEST_CASE("test ssl client") {
251251
auto result = client.get("https://www.bing.com");
252252
CHECK(result.status >= 200);
253253
}
254-
254+
{
255+
coro_http_client client{};
256+
auto ret = client.get("https://baidu.com");
257+
client.reset();
258+
ret = client.get("http://cn.bing.com");
259+
std::cout << ret.status << std::endl;
260+
client.reset();
261+
ret = client.get("https://baidu.com");
262+
std::cout << ret.status << std::endl;
263+
}
255264
{
256265
coro_http_client client{};
257266
auto r =

0 commit comments

Comments
 (0)