8000 [HttpClient] fail properly when the server replies with HTTP/0.9 · symfony/symfony@f7ed6bf · GitHub
[go: up one dir, main page]

Skip to content

Commit f7ed6bf

Browse files
[HttpClient] fail properly when the server replies with HTTP/0.9
1 parent afd4027 commit f7ed6bf

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ public function __construct(CurlClientState $multi, $ch, array $options = null,
123123
}
124124

125125
curl_setopt($ch, \CURLOPT_WRITEFUNCTION, static function ($ch, string $data) use ($multi, $id): int {
126+
if ('H' === @curl_getinfo($ch, \CURLINFO_PRIVATE)) {
127+
$multi->handlesActivity[$id][] = null;
128+
$multi->handlesActivity[$id][] = new TransportException(sprintf('Unsupported protocol for "%s"', curl_getinfo($ch, \CURLINFO_EFFECTIVE_URL)));
129+
130+
return 0;
131+
}
132+
133+
curl_setopt($ch, \CURLOPT_WRITEFUNCTION, static function ($ch, string $data) use ($multi, $id): int {
134+
$multi->handlesActivity[$id][] = $data;
135+
136+
return \strlen($data);
137+
});
138+
126139
$multi->handlesActivity[$id][] = $data;
127140

128141
return \strlen($data);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ private static function addResponseHeaders(array $responseHeaders, array &$info,
270270
$debug .= "< \r\n";
271271

272272
if (!$info['http_code']) {
273-
throw new TransportException('Invalid or missing HTTP status line.');
273+
throw new TransportException(sprintf('Invalid or missing HTTP status line for "%s".', implode('', $info['url'])));
274274
}
275275
}
276276

@@ -350,7 +350,7 @@ public static function stream(iterable $responses, float $timeout = null): \Gene
350350

351351
if (\is_string($chunk = array_shift($multi->handlesActivity[$j]))) {
352352
if (null !== $response->inflate && false === $chunk = @inflate_add($response->inflate, $chunk)) {
353-
$multi->handlesActivity[$j] = [null, new TransportException('Error while processing content unencoding.')];
353+
$multi->handlesActivity[$j] = [null, new TransportException(sprintf('Error while processing content unencoding for "%s".', $response->getInfo('url')))];
354354
continue;
355355
}
356356

0 commit comments

Comments
 (0)
0