Open a new connection for a redirect after sending Connection: close (#2645)

Without keep-alive, the client sends "Connection: close", but before
following a redirect it disconnected only when the response repeated
the option. RFC 9112 (section 9.6) lets a server close the connection
without repeating it, and a client that sent "close" must not send
another request on that connection. The redirected request was written
to the closing connection and failed with "Failed to read connection"
whenever the server closed it first. The client now disconnects before
a redirect or an auth retry whenever the request asked for the close.

Co-authored-by: Wleeaf <179125857+wleeaf@users.noreply.github.com>
This commit is contained in:
WleeafandWleeaf authored and GitHub committed 2026-10-25 17:19:34 -04:00
1 parent a210b43e11
commit 5ceef83c54
2 files changed
+73 -3

No files matched your search

+4 -3
View File
@@ -16278,9 +16278,10 @@ inline bool ClientImpl::handle_request(Stream &strm, Request &req,
// to call it from a different thread since it's a thread-safety issue
// to do these things to the socket if another thread is using the socket.
std::lock_guard<std::mutex> guard(socket_mutex_);
// Also when the request asked for it (e.g. a body that was never sent),
// so that a redirect or an auth retry below does not reuse the socket.
if (socket_should_be_closed_when_request_is_done_ ||
// Also when the request asked for it (e.g. a body that was never sent,
// or "Connection: close"), so that a redirect or an auth retry below does
// not reuse the socket.
if (socket_should_be_closed_when_request_is_done_ || close_connection ||
detail::has_header_token(res.headers, "Connection", "close") ||
(res.version == "HTTP/1.0" && res.reason != "Connection established")) {
disconnect(/*gracefully=*/true);