Skip to content
Open
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
12 changes: 10 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,16 @@ public function recycleConnectionFromRequest(Request $request, ?Response $respon
$connection->onConnect = $connection->onClose = $connection->onMessage = $connection->onError = null;
$request_header_connection = strtolower($request->getHeaderLine('Connection'));
$response_header_connection = $response ? strtolower($response->getHeaderLine('Connection')) : '';
// Close Connection without header Connection: keep-alive
if ('keep-alive' !== $request_header_connection || 'keep-alive' !== $response_header_connection || $request->getProtocolVersion() !== '1.1') {
// RFC 7230 §6.3: HTTP/1.1 connections are persistent by default — servers usually OMIT
// the Connection header. Close only when either side explicitly says "close", the
// protocol is not 1.1, or there is no response (transport-level failure).
// (Previously required both sides to literally send "Connection: keep-alive", which
// almost never happens with real-world servers, so the pool never reused connections.)
$shouldClose = !$response
|| $request->getProtocolVersion() !== '1.1'
|| str_contains($request_header_connection, 'close')
|| str_contains($response_header_connection, 'close');
if ($shouldClose) {
$connection->close();
}
$request->detachConnection($connection);
Expand Down