8000 [HttpClient] Fix dealing with "HTTP/1.1 000 " responses · symfony/symfony@9dec964 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9dec964

Browse files
[HttpClient] Fix dealing with "HTTP/1.1 000 " responses
1 parent 1e3d60b commit 9dec964

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

src/Symfony/Component/HttpClient/Response/CurlResponse.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,8 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
339339
}
340340

341341
if ('' !== $data) {
342-
try {
343-
// Regular header line: add it to the list
344-
self::addResponseHeaders([$data], $info, $headers);
345-
} catch (TransportException $e) {
346-
$multi->handlesActivity[$id][] = null;
347-
$multi->handlesActivity[$id][] = $e;
348-
349-
return \strlen($data);
350-
}
342+
// Regular header line: add it to the list
343+
self::addResponseHeaders([$data], $info, $headers);
351344

352345
if (!str_starts_with($data, 'HTTP/')) {
353346
if (0 === stripos($data, 'Location:')) {

src/Symfony/Component/HttpClient/Response/ResponseTrait.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ private static function initialize(self $response): void
260260
private static function addResponseHeaders(array $responseHeaders, array &$info, array &$headers, string &$debug = ''): void
261261
{
262262
foreach ($responseHeaders as $h) {
263-
if (11 <= \strlen($h) && '/' === $h[4] && preg_match('#^HTTP/\d+(?:\.\d+)? ([1-9]\d\d)(?: |$)#', $h, $m)) {
263+
if (11 <= \strlen($h) && '/' === $h[4] && preg_match('#^HTTP/\d+(?:\.\d+)? (\d\d\d)(?: |$)#', $h, $m)) {
264264
if ($headers) {
265265
$debug .= "< \r\n";
266266
$headers = [];
@@ -275,10 +275,6 @@ private static function addResponseHeaders(array $responseHeaders, array &$info,
275275
}
276276

277277
$debug .= "< \r\n";
278-
279-
if (!$info['http_code']) {
280-
throw new TransportException(sprintf('Invalid or missing HTTP status line for "%s".', implode('', $info['url'])));
281-
}
282278
}
283279

284280
private function checkStatusCode()

src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ public function invalidResponseFactoryProvider()
6666
];
6767
}
6868

69+
public function testZeroStatusCode()
70+
{
71+
$client = new MockHttpClient(new MockResponse('', ['response_headers' => ['HTTP/1.1 000 ']]));
72+
$response = $client->request('GET', 'https://foo.bar');
73+
$this->assertSame(0, $response->getStatusCode());
74+
}
75+
6976
public function testThrowExceptionInBodyGenerator()
7077
{
7178
$mockHttpClient = new MockHttpClient([

0 commit comments

Comments
 (0)
0