Merge pull request #9592 from wissem/add-response-duration-http-requests

Add response info for HTTP requests in CurlDownloader
main
Jordi Boggiano 4 years ago committed by GitHub
commit 296bab1292
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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;
}
}

@ -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']);

@ -0,0 +1,32 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* 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;
}
}
Loading…
Cancel
Save