Add all curl_getinfo into the response and exception for curl requests
parent
a5d79db0a7
commit
bdecb4711d
|
@ -20,7 +20,7 @@ class TransportException extends \RuntimeException
|
|||
protected $headers;
|
||||
protected $response;
|
||||
protected $statusCode;
|
||||
protected $totalResponseTime;
|
||||
protected $responseInfo;
|
||||
|
||||
public function setHeaders($headers)
|
||||
{
|
||||
|
@ -52,13 +52,19 @@ class TransportException extends \RuntimeException
|
|||
return $this->statusCode;
|
||||
}
|
||||
|
||||
public function getTotalResponseTime()
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getResponseInfo()
|
||||
{
|
||||
return $this->totalResponseTime;
|
||||
return $this->responseInfo;
|
||||
}
|
||||
|
||||
public function setTotalResponseTime($totalResponseTime)
|
||||
/**
|
||||
* @param array $responseInfo
|
||||
*/
|
||||
public function setResponseInfo($responseInfo)
|
||||
{
|
||||
$this->totalResponseTime = $totalResponseTime;
|
||||
$this->responseInfo = $responseInfo;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -303,9 +303,8 @@ class CurlDownloader
|
|||
if (!$error && function_exists('curl_strerror')) {
|
||||
$error = curl_strerror($errno);
|
||||
}
|
||||
|
||||
$exception = new TransportException('curl error '.$errno.' while downloading '.Url::sanitize($progress['url']).': '.$error);
|
||||
$exception->setTotalResponseTime(isset($progress['total_time_us']) ? $progress['total_time_us'] : null);
|
||||
$exception->setResponseInfo($progress);
|
||||
throw $exception;
|
||||
}
|
||||
$statusCode = $progress['http_code'];
|
||||
|
@ -324,14 +323,12 @@ class CurlDownloader
|
|||
rewind($job['bodyHandle']);
|
||||
$contents = stream_get_contents($job['bodyHandle']);
|
||||
}
|
||||
$response = new Response(array('url' => $progress['url']), $statusCode, $headers, $contents);
|
||||
$response->setTotalResponseTime(isset($progress['total_time_us']) ? $progress['total_time_us'] : null);
|
||||
$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->setTotalResponseTime(isset($progress['total_time_us']) ? $progress['total_time_us'] : null);
|
||||
$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;
|
||||
}
|
||||
}
|
|
@ -20,7 +20,6 @@ class Response
|
|||
private $code;
|
||||
private $headers;
|
||||
private $body;
|
||||
private $totalResponseTime;
|
||||
|
||||
public function __construct(array $request, $code, array $headers, $body)
|
||||
{
|
||||
|
@ -70,20 +69,6 @@ class Response
|
|||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Total duration time it took for the response in micro seconds
|
||||
* @return int|null
|
||||
*/
|
||||
public function getTotalResponseTime()
|
||||
{
|
||||
return $this->totalResponseTime;
|
||||
}
|
||||
|
||||
public function setTotalResponseTime($totalResponseTime)
|
||||
{
|
||||
$this->totalResponseTime = $totalResponseTime;
|
||||
}
|
||||
|
||||
public function decodeJson()
|
||||
{
|
||||
return JsonFile::parseJson($this->body, $this->request['url']);
|
||||
|
|
Loading…
Reference in New Issue