From 472f78bff1db203bd1ff89bfcc8514ae89b8b0f6 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 29 Oct 2020 22:39:26 +0100 Subject: [PATCH] Auto-disable misbehaving curl downloader on php 5, refs #9002 --- src/Composer/Util/HttpDownloader.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Composer/Util/HttpDownloader.php b/src/Composer/Util/HttpDownloader.php index a317b9486..8d7bc45b5 100644 --- a/src/Composer/Util/HttpDownloader.php +++ b/src/Composer/Util/HttpDownloader.php @@ -80,7 +80,27 @@ class HttpDownloader list($job) = $this->addJob(array('url' => $url, 'options' => $options, 'copyTo' => false), true); $this->wait($job['id']); - return $this->getResponse($job['id']); + $response = $this->getResponse($job['id']); + + // check for failed curl response (empty body but successful looking response) + if ( + $this->curl + && PHP_VERSION_ID < 70000 + && $response->getBody() === null + && $response->getStatusCode() === 200 + && $response->getHeader('content-length') !== '0' + ) { + $this->io->writeError('cURL downloader failed to return a response, disabling it and proceeding in slow mode.'); + + $this->curl = null; + + list($job) = $this->addJob(array('url' => $url, 'options' => $options, 'copyTo' => false), true); + $this->wait($job['id']); + + $response = $this->getResponse($job['id']); + } + + return $response; } public function add($url, $options = array())