From 605ed540181d79072ea78303c32e03aa5fe96df3 Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Fri, 13 Nov 2026 00:22:16 +0100 Subject: [PATCH] Detect HEAD requests case-insensitively in the cURL transport The cURL transport upper-cased the method for the request line but set CURLOPT_NOBODY only for exactly "HEAD". A lower-case "head", which can come from a PSR-7 request or a direct transport call, was sent as a custom HEAD request with NOBODY disabled, so cURL waited for the body announced by Content-Length until the connection was closed or the request timed out. Co-Authored-By: Claude Opus 5.5 --- Tests/Transport/HeadRequestTest.php | 55 +++++++++++++++++++++++++++++ Tests/stubs/content_length.php | 16 +++++++++ docs/overview.md | 4 ++- src/Transport/Curl.php | 2 +- 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 Tests/Transport/HeadRequestTest.php create mode 100644 Tests/stubs/content_length.php diff --git a/Tests/Transport/HeadRequestTest.php b/Tests/Transport/HeadRequestTest.php new file mode 100644 index 00000000..edcaa2a3 --- /dev/null +++ b/Tests/Transport/HeadRequestTest.php @@ -0,0 +1,55 @@ + [$transport, $method]; + } + } + } + + #[DataProvider('transportAndMethodProvider')] + public function testHeadRequestDoesNotWaitForABody(string $transportClass, string $method): void + { + if (!$transportClass::isSupported()) { + $this->markTestSkipped(sprintf('The "%s" adapter is not supported in this environment.', $transportClass)); + } + + if (!\defined('JTEST_HTTP_STUB') && getenv('JTEST_HTTP_STUB') == '') { + $this->markTestSkipped('The Transport test stub has not been configured'); + } + + $stubUrl = \defined('JTEST_HTTP_STUB') ? JTEST_HTTP_STUB : getenv('JTEST_HTTP_STUB'); + $url = substr($stubUrl, 0, strrpos($stubUrl, '/') + 1) . 'content_length.php'; + + $response = (new $transportClass([]))->request($method, new Uri($url), null, [], 5); + + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('100', $response->getHeaderLine('Content-Length')); + $this->assertSame('', (string) $response->getBody()); + } +} diff --git a/Tests/stubs/content_length.php b/Tests/stubs/content_length.php new file mode 100644 index 00000000..dbcf42cd --- /dev/null +++ b/Tests/stubs/content_length.php @@ -0,0 +1,16 @@ +