From db6170db896e69498d14369f8c06496b8a19b7fd Mon Sep 17 00:00:00 2001 From: owner888 <4317332+owner888@users.noreply.github.com> Date: Fri, 3 Jul 2026 23:19:21 +0700 Subject: [PATCH] Fix keep-alive: HTTP/1.1 is persistent by default (RFC 7230), don't require explicit keep-alive header --- src/Client.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index f3db692..0439871 100644 --- a/src/Client.php +++ b/src/Client.php @@ -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);