Skip to content

Commit 44f7438

Browse files
committed
fix: handle HTTP/2 responses without a reason phrase in CURLRequest
1 parent e7bf630 commit 44f7438

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

system/HTTP/CURLRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,14 +504,14 @@ protected function setResponseHeaders(array $headers = [])
504504
$this->response->setHeader($title, $value);
505505
}
506506
} elseif (str_starts_with($header, 'HTTP')) {
507-
preg_match('#^HTTP\/([12](?:\.[01])?) (\d+) (.+)#', $header, $matches);
507+
preg_match('#^HTTP\/([12](?:\.[01])?) (\d+)(?: (.+))?#', $header, $matches);
508508

509509
if (isset($matches[1])) {
510510
$this->response->setProtocolVersion($matches[1]);
511511
}
512512

513513
if (isset($matches[2])) {
514-
$this->response->setStatusCode((int) $matches[2], $matches[3] ?? null);
514+
$this->response->setStatusCode((int) $matches[2], $matches[3] ?? '');
515515
}
516516
}
517517
}

tests/system/Cookie/CookieTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public function testArrayAccessOfCookie(): void
301301
$this->assertSame($cookie['path'], $cookie->getPath());
302302

303303
$this->expectException('InvalidArgumentException');
304-
$cookie['expiry']; // @phpstan-ignore expr.resultUnused
304+
$cookie['expiry'];
305305
}
306306

307307
public function testCannotSetPropertyViaArrayAccess(): void

tests/system/HTTP/CURLRequestTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,23 @@ public function testResponseHeadersShortProtocol(): void
10411041
$this->assertSame(235, $response->getStatusCode());
10421042
}
10431043

1044+
public function testResponseHeadersWithoutReasonPhrase(): void
1045+
{
1046+
// HTTP/2 does not include a reason phrase per RFC 7540.
1047+
// curl synthesizes the status line as "HTTP/2 200" with no trailing reason.
1048+
$request = $this->getRequest([
1049+
'baseURI' => 'http://www.foo.com/api/v1/',
1050+
'delay' => 100,
1051+
]);
1052+
1053+
$request->setOutput("HTTP/2 200\x0d\x0aContent-Type: text/html\x0d\x0a\x0d\x0aHi there");
1054+
$response = $request->get('bogus');
1055+
1056+
$this->assertSame('2.0', $response->getProtocolVersion());
1057+
$this->assertSame(200, $response->getStatusCode());
1058+
$this->assertSame('OK', $response->getReasonPhrase());
1059+
}
1060+
10441061
public function testPostFormEncoded(): void
10451062
{
10461063
$params = [

0 commit comments

Comments
 (0)