[HttpClient] fail properly when the server replies with HTTP/0.9

This commit is contained in:
Nicolas Grekas 2020-09-10 20:19:03 +02:00
parent afd4027c11
commit 96759af1da
2 changed files with 15 additions and 2 deletions

View File

@ -123,6 +123,19 @@ final class CurlResponse implements ResponseInterface
}
curl_setopt($ch, \CURLOPT_WRITEFUNCTION, static function ($ch, string $data) use ($multi, $id): int {
if ('H' === (curl_getinfo($ch, \CURLINFO_PRIVATE)[0] ?? null)) {
$multi->handlesActivity[$id][] = null;
$multi->handlesActivity[$id][] = new TransportException(sprintf('Unsupported protocol for "%s"', curl_getinfo($ch, \CURLINFO_EFFECTIVE_URL)));
return 0;
}
curl_setopt($ch, \CURLOPT_WRITEFUNCTION, static function ($ch, string $data) use ($multi, $id): int {
$multi->handlesActivity[$id][] = $data;
return \strlen($data);
});
$multi->handlesActivity[$id][] = $data;
return \strlen($data);

View File

@ -270,7 +270,7 @@ trait ResponseTrait
$debug .= "< \r\n";
if (!$info['http_code']) {
throw new TransportException('Invalid or missing HTTP status line.');
throw new TransportException(sprintf('Invalid or missing HTTP status line for "%s".', implode('', $info['url'])));
}
}
@ -350,7 +350,7 @@ trait ResponseTrait
if (\is_string($chunk = array_shift($multi->handlesActivity[$j]))) {
if (null !== $response->inflate && false === $chunk = @inflate_add($response->inflate, $chunk)) {
$multi->handlesActivity[$j] = [null, new TransportException('Error while processing content unencoding.')];
$multi->handlesActivity[$j] = [null, new TransportException(sprintf('Error while processing content unencoding for "%s".', $response->getInfo('url')))];
continue;
}