Tweaks to new proxying code, refs #9324
parent
62fd612e63
commit
62eff8e979
|
@ -234,7 +234,7 @@ class CurlDownloader
|
|||
'reject' => $reject,
|
||||
);
|
||||
|
||||
$usingProxy = $proxy->getLastProxy(' using proxy (%s)');
|
||||
$usingProxy = $proxy->getFormattedUrl(' using proxy (%s)');
|
||||
$ifModified = false !== stripos(implode(',', $options['http']['header']), 'if-modified-since:') ? ' if modified' : '';
|
||||
if ($attributes['redirects'] === 0) {
|
||||
$this->io->writeError('Downloading ' . Url::sanitize($url) . $usingProxy . $ifModified, true, IOInterface::DEBUG);
|
||||
|
|
|
@ -85,34 +85,42 @@ class ProxyManager
|
|||
$scheme = parse_url($requestUrl, PHP_URL_SCHEME) ?: 'http';
|
||||
$proxyUrl = '';
|
||||
$options = array();
|
||||
$lastProxy = '';
|
||||
$formattedProxyUrl = '';
|
||||
|
||||
if ($this->hasProxy && $this->fullProxy[$scheme]) {
|
||||
if ($this->noProxy($requestUrl)) {
|
||||
$lastProxy = 'excluded by no_proxy';
|
||||
$formattedProxyUrl = 'excluded by no_proxy';
|
||||
} else {
|
||||
$proxyUrl = $this->fullProxy[$scheme];
|
||||
$options = $this->streams[$scheme]['options'];
|
||||
ProxyHelper::setRequestFullUri($requestUrl, $options);
|
||||
$lastProxy = $this->safeProxy[$scheme];
|
||||
$formattedProxyUrl = $this->safeProxy[$scheme];
|
||||
}
|
||||
}
|
||||
|
||||
return new RequestProxy($proxyUrl, $options, $lastProxy);
|
||||
return new RequestProxy($proxyUrl, $options, $formattedProxyUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a proxy is being used
|
||||
*
|
||||
* @param string|null $message Set to safe proxy values
|
||||
* @return bool If false any error will be in $message
|
||||
*/
|
||||
public function getStatus(&$message)
|
||||
public function isProxying()
|
||||
{
|
||||
$message = $this->hasProxy ? $this->info : $this->error;
|
||||
return $this->hasProxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns proxy configuration info which can be shown to the user
|
||||
*
|
||||
* @return string|null Safe proxy URL or an error message if setting up proxy failed or null if no proxy was configured
|
||||
*/
|
||||
public function getFormattedProxy()
|
||||
{
|
||||
return $this->hasProxy ? $this->info : $this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes proxy values from the environment
|
||||
*/
|
||||
|
|
|
@ -22,21 +22,19 @@ class RequestProxy
|
|||
{
|
||||
private $contextOptions;
|
||||
private $isSecure;
|
||||
private $lastProxy;
|
||||
private $safeUrl;
|
||||
private $formattedUrl;
|
||||
private $url;
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @param array $contextOptions
|
||||
* @param string $lastProxy
|
||||
* @param string $formattedUrl
|
||||
*/
|
||||
public function __construct($url, array $contextOptions, $lastProxy)
|
||||
public function __construct($url, array $contextOptions, $formattedUrl)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->contextOptions = $contextOptions;
|
||||
$this->lastProxy = $lastProxy;
|
||||
$this->safeUrl = Url::sanitize($url);
|
||||
$this->formattedUrl = $formattedUrl;
|
||||
$this->isSecure = 0 === strpos($url, 'https://');
|
||||
}
|
||||
|
||||
|
@ -56,12 +54,12 @@ class RequestProxy
|
|||
* @param string|null $format Output format specifier
|
||||
* @return string Safe proxy, no proxy or empty
|
||||
*/
|
||||
public function getLastProxy($format = '')
|
||||
public function getFormattedUrl($format = '')
|
||||
{
|
||||
$result = '';
|
||||
if ($this->lastProxy) {
|
||||
if ($this->formattedUrl) {
|
||||
$format = $format ?: '%s';
|
||||
$result = sprintf($format, $this->lastProxy);
|
||||
$result = sprintf($format, $this->formattedUrl);
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
|
|
@ -255,7 +255,7 @@ class RemoteFilesystem
|
|||
$ctx = StreamContextFactory::getContext($fileUrl, $options, array('notification' => array($this, 'callbackGet')));
|
||||
|
||||
$proxy = ProxyManager::getInstance()->getProxyForRequest($fileUrl);
|
||||
$usingProxy = $proxy->getLastProxy(' using proxy (%s)');
|
||||
$usingProxy = $proxy->getFormattedUrl(' using proxy (%s)');
|
||||
$this->io->writeError((strpos($origFileUrl, 'http') === 0 ? 'Downloading ' : 'Reading ') . Url::sanitize($origFileUrl) . $usingProxy, true, IOInterface::DEBUG);
|
||||
unset($origFileUrl, $proxy, $usingProxy);
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ class ProxyManagerTest extends TestCase
|
|||
$this->assertSame($expectedOptions, $proxy->getContextOptions());
|
||||
$this->assertSame($expectedSecure, $proxy->isSecure());
|
||||
|
||||
$message = $proxy->getLastProxy();
|
||||
$message = $proxy->getFormattedUrl();
|
||||
|
||||
if ($expectedMessage) {
|
||||
$condition = stripos($message, $expectedMessage) !== false;
|
||||
|
@ -134,7 +134,8 @@ class ProxyManagerTest extends TestCase
|
|||
{
|
||||
$_SERVER = array_merge($_SERVER, $server);
|
||||
$proxyManager = ProxyManager::getInstance();
|
||||
$status = $proxyManager->getStatus($message);
|
||||
$status = $proxyManager->isProxying();
|
||||
$message = $proxyManager->getFormattedProxy();
|
||||
|
||||
$this->assertSame($expectedStatus, $status);
|
||||
|
||||
|
|
|
@ -38,17 +38,17 @@ class RequestProxyTest extends TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataLastProxy
|
||||
* @dataProvider dataProxyUrl
|
||||
*/
|
||||
public function testGetLastProxyFormat($url, $format, $expected)
|
||||
public function testGetFormattedUrlFormat($url, $format, $expected)
|
||||
{
|
||||
$proxy = new RequestProxy($url, array(), $url);
|
||||
|
||||
$message = $proxy->getLastProxy($format);
|
||||
$message = $proxy->getFormattedUrl($format);
|
||||
$this->assertSame($expected, $message);
|
||||
}
|
||||
|
||||
public function dataLastProxy()
|
||||
public function dataProxyUrl()
|
||||
{
|
||||
$format = 'proxy (%s)';
|
||||
|
||||
|
|
Loading…
Reference in New Issue