Skip to content

Commit cc519aa

Browse files
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 ------- c764b5c [HttpClient] fix PHP warning + accept status code >= 600
2 parents bce3760 + c764b5c commit cc519aa

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,15 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
312312
}
313313

314314
if ("\r\n" !== $data) {
315-
// Regular header line: add it to the list
316-
self::addResponseHeaders([substr($data, 0, -2)], $info, $headers);
315+
try {
316+
// Regular header line: add it to the list
317+
self::addResponseHeaders([substr($data, 0, -2)], $info, $headers);
318+
} catch (TransportException $e) {
319+
$multi->handlesActivity[$id][] = null;
320+
$multi->handlesActivity[$id][] = $e;
321+
322+
return \strlen($data);
323+
}
317324

318325
if (0 !== strpos($data, 'HTTP/')) {
319326
if (0 === stripos($data, 'Location:')) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ private static function initialize(self $response): void
253253
private static function addResponseHeaders(array $responseHeaders, array &$info, array &$headers, string &$debug = ''): void
254254
{
255255
foreach ($responseHeaders as $h) {
256-
if (11 <= \strlen($h) && '/' === $h[4] && preg_match('#^HTTP/\d+(?:\.\d+)? ([12345]\d\d)(?: |$)#', $h, $m)) {
256+
if (11 <= \strlen($h) && '/' === $h[4] && preg_match('#^HTTP/\d+(?:\.\d+)? ([1-9]\d\d)(?: |$)#', $h, $m)) {
257257
if ($headers) {
258258
$debug .= "< \r\n";
259259
$headers = [];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy