bug #36823 [HttpClient] fix PHP warning + accept status code >= 600 (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpClient] fix PHP warning + accept status code >= 600

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #36717
| License       | MIT
| Doc PR        | -

This fixes the PHP warning reported in the linked issue.

This also relaxes the accepted status codes, with https://www.linkedin.com/company/linkedin/ as an example that returns a non-conformant one (`999`).

These are now handled as 5xx codes, ie they trigger a ServerException.

Commits
-------

c764b5c36e [HttpClient] fix PHP warning + accept status code >= 600
This commit is contained in:
Nicolas Grekas 2020-05-16 11:09:03 +02:00
commit cc519aa5a9
2 changed files with 10 additions and 3 deletions

View File

@ -312,8 +312,15 @@ final class CurlResponse implements ResponseInterface
}
if ("\r\n" !== $data) {
// Regular header line: add it to the list
self::addResponseHeaders([substr($data, 0, -2)], $info, $headers);
try {
// Regular header line: add it to the list
self::addResponseHeaders([substr($data, 0, -2)], $info, $headers);
} catch (TransportException $e) {
$multi->handlesActivity[$id][] = null;
$multi->handlesActivity[$id][] = $e;
return \strlen($data);
}
if (0 !== strpos($data, 'HTTP/')) {
if (0 === stripos($data, 'Location:')) {

View File

@ -253,7 +253,7 @@ trait ResponseTrait
private static function addResponseHeaders(array $responseHeaders, array &$info, array &$headers, string &$debug = ''): void
{
foreach ($responseHeaders as $h) {
if (11 <= \strlen($h) && '/' === $h[4] && preg_match('#^HTTP/\d+(?:\.\d+)? ([12345]\d\d)(?: |$)#', $h, $m)) {
if (11 <= \strlen($h) && '/' === $h[4] && preg_match('#^HTTP/\d+(?:\.\d+)? ([1-9]\d\d)(?: |$)#', $h, $m)) {
if ($headers) {
$debug .= "< \r\n";
$headers = [];