Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d793d03

Browse files
[HttpClient] Fix dealing with "HTTP/1.1 000 " responses
1 parent 276ef95 commit d793d03

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
@@ -340,15 +340,8 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
340340
}
341341

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

353346
if (!str_starts_with($data, 'HTTP/')) {
354347
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)