From 22f798daf2a40fd513133d437ce88010f5524fd7 Mon Sep 17 00:00:00 2001 From: Paul Kolomiets Date: Sat, 19 Apr 2025 08:20:03 +0300 Subject: [PATCH] Do not close socket in case of protocol upgrade Http should not processing should stop at this point, socket will be reused for another protocol. --- httplib.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/httplib.h b/httplib.h index cb182c4129..7cfe6fc25e 100644 --- a/httplib.h +++ b/httplib.h @@ -7711,8 +7711,9 @@ inline bool ClientImpl::send_(Request &req, Response &res, Error &error) { socket_requests_are_from_thread_ = std::thread::id(); } - if (socket_should_be_closed_when_request_is_done_ || close_connection || - !ret) { + if ((socket_should_be_closed_when_request_is_done_ || close_connection || + !ret) && + res.status != StatusCode::SwitchingProtocol_101) { shutdown_ssl(socket_, true); shutdown_socket(socket_); close_socket(socket_); @@ -8225,7 +8226,8 @@ inline bool ClientImpl::process_request(Stream &strm, Request &req, } } - if (res.status != StatusCode::NotModified_304) { + if (res.status != StatusCode::NotModified_304 && + res.status != StatusCode::SwitchingProtocol_101) { int dummy_status; if (!detail::read_content(strm, res, (std::numeric_limits::max)(), dummy_status, std::move(progress),