diff --git a/src/Composer/Downloader/TransportException.php b/src/Composer/Downloader/TransportException.php index c682df080..68c73542f 100644 --- a/src/Composer/Downloader/TransportException.php +++ b/src/Composer/Downloader/TransportException.php @@ -20,6 +20,7 @@ class TransportException extends \RuntimeException protected $headers; protected $response; protected $statusCode; + protected $responseInfo = array(); public function setHeaders($headers) { @@ -50,4 +51,20 @@ class TransportException extends \RuntimeException { return $this->statusCode; } + + /** + * @return array + */ + public function getResponseInfo() + { + return $this->responseInfo; + } + + /** + * @param array $responseInfo + */ + public function setResponseInfo(array $responseInfo) + { + $this->responseInfo = $responseInfo; + } } diff --git a/src/Composer/Util/Http/CurlDownloader.php b/src/Composer/Util/Http/CurlDownloader.php index 5345f5ce3..6f6d69352 100644 --- a/src/Composer/Util/Http/CurlDownloader.php +++ b/src/Composer/Util/Http/CurlDownloader.php @@ -303,7 +303,9 @@ class CurlDownloader if (!$error && function_exists('curl_strerror')) { $error = curl_strerror($errno); } - throw new TransportException('curl error '.$errno.' while downloading '.Url::sanitize($progress['url']).': '.$error); + $exception = new TransportException('curl error '.$errno.' while downloading '.Url::sanitize($progress['url']).': '.$error); + $exception->setResponseInfo($progress); + throw $exception; } $statusCode = $progress['http_code']; rewind($job['headerHandle']); @@ -321,12 +323,12 @@ class CurlDownloader rewind($job['bodyHandle']); $contents = stream_get_contents($job['bodyHandle']); } - $response = new Response(array('url' => $progress['url']), $statusCode, $headers, $contents); + $response = new CurlResponse(array('url' => $progress['url']), $statusCode, $headers, $contents, $progress); $this->io->writeError('['.$statusCode.'] '.Url::sanitize($progress['url']), true, IOInterface::DEBUG); } else { rewind($job['bodyHandle']); $contents = stream_get_contents($job['bodyHandle']); - $response = new Response(array('url' => $progress['url']), $statusCode, $headers, $contents); + $response = new CurlResponse(array('url' => $progress['url']), $statusCode, $headers, $contents, $progress); $this->io->writeError('['.$statusCode.'] '.Url::sanitize($progress['url']), true, IOInterface::DEBUG); } fclose($job['bodyHandle']); diff --git a/src/Composer/Util/Http/CurlResponse.php b/src/Composer/Util/Http/CurlResponse.php new file mode 100644 index 000000000..82f725266 --- /dev/null +++ b/src/Composer/Util/Http/CurlResponse.php @@ -0,0 +1,32 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Util\Http; + +class CurlResponse extends Response +{ + private $curlInfo; + + public function __construct(array $request, $code, array $headers, $body, array $curlInfo) + { + parent::__construct($request, $code, $headers, $body); + $this->curlInfo = $curlInfo; + } + + /** + * @return array + */ + public function getCurlInfo() + { + return $this->curlInfo; + } +}