Skip to content

Commit acbfed6

Browse files
bug #38148 [HttpClient] fail properly when the server replies with HTTP/0.9 (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpClient] fail properly when the server replies with HTTP/0.9 | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Fix #37923 | License | MIT | Doc PR | - Commits ------- 96759af1da [HttpClient] fail properly when the server replies with HTTP/0.9
2 parents a9319a5 + 5c46c40 commit acbfed6

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

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)[0] ?? null)) {
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);

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)