Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix reset client #657

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/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
10 changes: 10 additions & 0 deletions tests/test_cinatra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,16 @@ TEST_CASE("test ssl client") {
};
async_simple::coro::syncAwait(lazy());
}
{
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 result = client.get("https://www.bing.com");
Expand Down
Loading