Merge pull request #9592 from wissem/add-response-duration-http-requests
Add response info for HTTP requests in CurlDownloaderpull/9594/head
commit
296bab1292
|
@ -20,6 +20,7 @@ class TransportException extends \RuntimeException
|
||||||
protected $headers;
|
protected $headers;
|
||||||
protected $response;
|
protected $response;
|
||||||
protected $statusCode;
|
protected $statusCode;
|
||||||
|
protected $responseInfo = array();
|
||||||
|
|
||||||
public function setHeaders($headers)
|
public function setHeaders($headers)
|
||||||
{
|
{
|
||||||
|
@ -50,4 +51,20 @@ class TransportException extends \RuntimeException
|
||||||
{
|
{
|
||||||
return $this->statusCode;
|
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')) {
|
if (!$error && function_exists('curl_strerror')) {
|
||||||
$error = curl_strerror($errno);
|
$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'];
|
$statusCode = $progress['http_code'];
|
||||||
rewind($job['headerHandle']);
|
rewind($job['headerHandle']);
|
||||||
|
@ -321,12 +323,12 @@ class CurlDownloader
|
||||||
rewind($job['bodyHandle']);
|
rewind($job['bodyHandle']);
|
||||||
$contents = stream_get_contents($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);
|
$this->io->writeError('['.$statusCode.'] '.Url::sanitize($progress['url']), true, IOInterface::DEBUG);
|
||||||
} else {
|
} else {
|
||||||
rewind($job['bodyHandle']);
|
rewind($job['bodyHandle']);
|
||||||
$contents = stream_get_contents($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);
|
$this->io->writeError('['.$statusCode.'] '.Url::sanitize($progress['url']), true, IOInterface::DEBUG);
|
||||||
}
|
}
|
||||||
fclose($job['bodyHandle']);
|
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…
Reference in New Issue