[HttpClient] Invalid HTTP status codes raise a warning using CurlHttpClient

Symfony version(s) affected: 5.0.8

Description
When sending a GET request that is answered with a 999 status code (which is horrible behavior, no doubt), a warning is raised.

Is there a way to prevent this?

Warning: curl_multi_exec(): Could not call the CURLOPT_HEADERFUNCTION in /vendor/symfony/http-client/Response/CurlResponse.php on line 261

[...]

Fatal error: Uncaught Symfony\Component\HttpClient\Exception\TransportException: Invalid or missing HTTP status line. in /vendor/symfony/http-client/Response/ResponseTrait.php on line 273

Symfony\Component\HttpClient\Exception\TransportException: Invalid or missing HTTP status line. in /vendor/symfony/http-client/Response/ResponseTrait.php on line 273

At least I think it is the 999 that breaks things, I am using Symfony’s HttpClient within a crawler and a link similar to https://www.linkedin.com/company/linkedin/ made it break.

How to reproduce

$client = new \Symfony\Component\HttpClient\CurlHttpClient();

$response = $client->request('GET', 'https://www.linkedin.com/company/linkedin/');
$contents = $response->getContent();

If that LinkedIn link does not return a 999 for you, you will probably need to manually set up a site that does to encounter the error. Not sure how they decide when to respond with 999. While gathering information for this report it returned the 999 in Chrome for me as well but eventually also worked once or twice. Probably security measures based on User-Agent and IP.

More people plagued by this over here: https://stackoverflow.com/questions/27231113/999-error-code-on-head-request-to-linkedin.

1 possible answer(s) on “[HttpClient] Invalid HTTP status codes raise a warning using CurlHttpClient