1
0
Fork 0

Undid CS changes

pull/4907/head
cinamo 2016-02-11 14:29:37 +01:00
parent da44f46b9c
commit 4f5b4aff9c
1 changed files with 79 additions and 90 deletions

View File

@ -13,8 +13,8 @@
namespace Composer\Util; namespace Composer\Util;
use Composer\Config; use Composer\Config;
use Composer\Downloader\TransportException;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Downloader\TransportException;
/** /**
* @author François Pluchino <francois.pluchino@opendisplay.com> * @author François Pluchino <francois.pluchino@opendisplay.com>
@ -136,7 +136,6 @@ class RemoteFilesystem
/** /**
* @param array $headers array of returned headers like from getLastHeaders() * @param array $headers array of returned headers like from getLastHeaders()
* @param string $name header name (case insensitive) * @param string $name header name (case insensitive)
*
* @return string|null * @return string|null
*/ */
public function findHeaderValue(array $headers, $name) public function findHeaderValue(array $headers, $name)
@ -157,7 +156,6 @@ class RemoteFilesystem
/** /**
* @param array $headers array of returned headers like from getLastHeaders() * @param array $headers array of returned headers like from getLastHeaders()
*
* @return int|null * @return int|null
*/ */
public function findStatusCode(array $headers) public function findStatusCode(array $headers)
@ -185,6 +183,7 @@ class RemoteFilesystem
* *
* @throws TransportException|\Exception * @throws TransportException|\Exception
* @throws TransportException When the file could not be downloaded * @throws TransportException When the file could not be downloaded
*
* @return bool|string * @return bool|string
*/ */
protected function get($originUrl, $fileUrl, $additionalOptions = array(), $fileName = null, $progress = true) protected function get($originUrl, $fileUrl, $additionalOptions = array(), $fileName = null, $progress = true)
@ -228,8 +227,7 @@ class RemoteFilesystem
unset($tempAdditionalOptions); unset($tempAdditionalOptions);
$userlandFollow = isset($options['http']['follow_location']) && !$options['http']['follow_location']; $userlandFollow = isset($options['http']['follow_location']) && !$options['http']['follow_location'];
$this->io->writeError((substr($fileUrl, 0, 4) === 'http' ? 'Downloading ' : 'Reading ') . $fileUrl, true, $this->io->writeError((substr($fileUrl, 0, 4) === 'http' ? 'Downloading ' : 'Reading ') . $fileUrl, true, IOInterface::DEBUG);
IOInterface::DEBUG);
if (isset($options['github-token'])) { if (isset($options['github-token'])) {
$fileUrl .= (false === strpos($fileUrl, '?') ? '?' : '&') . 'access_token='.$options['github-token']; $fileUrl .= (false === strpos($fileUrl, '?') ? '?' : '&') . 'access_token='.$options['github-token'];
@ -250,8 +248,7 @@ class RemoteFilesystem
$fileUrl = 'http://' . gethostbyname('packagist.org') . substr($fileUrl, 20); $fileUrl = 'http://' . gethostbyname('packagist.org') . substr($fileUrl, 20);
} }
$ctx = StreamContextFactory::getContext($fileUrl, $options, $ctx = StreamContextFactory::getContext($fileUrl, $options, array('notification' => array($this, 'callbackGet')));
array('notification' => array($this, 'callbackGet')));
if ($this->progress && !$isRedirect) { if ($this->progress && !$isRedirect) {
$this->io->writeError(" Downloading: <comment>Connecting...</comment>", false); $this->io->writeError(" Downloading: <comment>Connecting...</comment>", false);
@ -317,8 +314,7 @@ class RemoteFilesystem
'<error>Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info</error>', '<error>Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info</error>',
)); ));
return $this->get($this->originUrl, $this->fileUrl, $additionalOptions, $this->fileName, return $this->get($this->originUrl, $this->fileUrl, $additionalOptions, $this->fileName, $this->progress);
$this->progress);
} }
throw $e; throw $e;
@ -339,8 +335,7 @@ class RemoteFilesystem
// fail 4xx and 5xx responses and capture the response // fail 4xx and 5xx responses and capture the response
if ($statusCode && $statusCode >= 400 && $statusCode <= 599) { if ($statusCode && $statusCode >= 400 && $statusCode <= 599) {
if (!$this->retry) { if (!$this->retry) {
$e = new TransportException('The "' . $this->fileUrl . '" file could not be downloaded (' . $http_response_header[0] . ')', $e = new TransportException('The "'.$this->fileUrl.'" file could not be downloaded ('.$http_response_header[0].')', $statusCode);
$statusCode);
$e->setHeaders($http_response_header); $e->setHeaders($http_response_header);
$e->setResponse($result); $e->setResponse($result);
$e->setStatusCode($statusCode); $e->setStatusCode($statusCode);
@ -380,8 +375,7 @@ class RemoteFilesystem
'<error>Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info</error>', '<error>Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info</error>',
)); ));
return $this->get($this->originUrl, $this->fileUrl, $additionalOptions, $this->fileName, return $this->get($this->originUrl, $this->fileUrl, $additionalOptions, $this->fileName, $this->progress);
$this->progress);
} }
} }
} }
@ -443,8 +437,7 @@ class RemoteFilesystem
if ($this->retry) { if ($this->retry) {
$this->retry = false; $this->retry = false;
$result = $this->get($this->originUrl, $this->fileUrl, $additionalOptions, $this->fileName, $result = $this->get($this->originUrl, $this->fileUrl, $additionalOptions, $this->fileName, $this->progress);
$this->progress);
if ($this->storeAuth && $this->config) { if ($this->storeAuth && $this->config) {
$authHelper = new AuthHelper($this->io, $this->config); $authHelper = new AuthHelper($this->io, $this->config);
@ -456,8 +449,7 @@ class RemoteFilesystem
} }
if (false === $result) { if (false === $result) {
$e = new TransportException('The "' . $this->fileUrl . '" file could not be downloaded: ' . $errorMessage, $e = new TransportException('The "'.$this->fileUrl.'" file could not be downloaded: '.$errorMessage, $errorCode);
$errorCode);
if (!empty($http_response_header[0])) { if (!empty($http_response_header[0])) {
$e->setHeaders($http_response_header); $e->setHeaders($http_response_header);
} }
@ -469,8 +461,7 @@ class RemoteFilesystem
'<error>Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info</error>', '<error>Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info</error>',
)); ));
return $this->get($this->originUrl, $this->fileUrl, $additionalOptions, $this->fileName, return $this->get($this->originUrl, $this->fileUrl, $additionalOptions, $this->fileName, $this->progress);
$this->progress);
} }
throw $e; throw $e;
@ -492,7 +483,6 @@ class RemoteFilesystem
* @param int $messageCode The message code * @param int $messageCode The message code
* @param int $bytesTransferred The loaded size * @param int $bytesTransferred The loaded size
* @param int $bytesMax The total size * @param int $bytesMax The total size
*
* @throws TransportException * @throws TransportException
*/ */
protected function callbackGet($notificationCode, $severity, $message, $messageCode, $bytesTransferred, $bytesMax) protected function callbackGet($notificationCode, $severity, $message, $messageCode, $bytesTransferred, $bytesMax)
@ -502,8 +492,7 @@ class RemoteFilesystem
if (400 === $messageCode) { if (400 === $messageCode) {
// This might happen if your host is secured by ssl client certificate authentication // This might happen if your host is secured by ssl client certificate authentication
// but you do not send an appropriate certificate // but you do not send an appropriate certificate
throw new TransportException("The '" . $this->fileUrl . "' URL could not be accessed: " . $message, throw new TransportException("The '" . $this->fileUrl . "' URL could not be accessed: " . $message, $messageCode);
$messageCode);
} }
// intentional fallthrough to the next case as the notificationCode // intentional fallthrough to the next case as the notificationCode
// isn't always consistent and we should inspect the messageCode for 401s // isn't always consistent and we should inspect the messageCode for 401s
@ -558,8 +547,7 @@ class RemoteFilesystem
$message = "\n".'Could not fetch '.$this->fileUrl.', please create a GitHub OAuth token '.($httpStatus === 404 ? 'to access private repos' : 'to go over the API rate limit'); $message = "\n".'Could not fetch '.$this->fileUrl.', please create a GitHub OAuth token '.($httpStatus === 404 ? 'to access private repos' : 'to go over the API rate limit');
$gitHubUtil = new GitHub($this->io, $this->config, null); $gitHubUtil = new GitHub($this->io, $this->config, null);
if (!$gitHubUtil->authorizeOAuth($this->originUrl) if (!$gitHubUtil->authorizeOAuth($this->originUrl)
&& (!$this->io->isInteractive() || !$gitHubUtil->authorizeOAuthInteractively($this->originUrl, && (!$this->io->isInteractive() || !$gitHubUtil->authorizeOAuthInteractively($this->originUrl, $message))
$message))
) { ) {
throw new TransportException('Could not authenticate against '.$this->originUrl, 401); throw new TransportException('Could not authenticate against '.$this->originUrl, 401);
} }
@ -567,8 +555,7 @@ class RemoteFilesystem
$message = "\n".'Could not fetch '.$this->fileUrl.', enter your ' . $this->originUrl . ' credentials ' .($httpStatus === 401 ? 'to access private repos' : 'to go over the API rate limit'); $message = "\n".'Could not fetch '.$this->fileUrl.', enter your ' . $this->originUrl . ' credentials ' .($httpStatus === 401 ? 'to access private repos' : 'to go over the API rate limit');
$gitLabUtil = new GitLab($this->io, $this->config, null); $gitLabUtil = new GitLab($this->io, $this->config, null);
if (!$gitLabUtil->authorizeOAuth($this->originUrl) if (!$gitLabUtil->authorizeOAuth($this->originUrl)
&& (!$this->io->isInteractive() || !$gitLabUtil->authorizeOAuthInteractively($this->scheme, && (!$this->io->isInteractive() || !$gitLabUtil->authorizeOAuthInteractively($this->scheme, $this->originUrl, $message))
$this->originUrl, $message))
) { ) {
throw new TransportException('Could not authenticate against '.$this->originUrl, 401); throw new TransportException('Could not authenticate against '.$this->originUrl, 401);
} }
@ -591,12 +578,10 @@ class RemoteFilesystem
} }
// fail if we already have auth // fail if we already have auth
if ($this->io->hasAuthentication($this->originUrl)) { if ($this->io->hasAuthentication($this->originUrl)) {
throw new TransportException("Invalid credentials for '" . $this->fileUrl . "', aborting.", throw new TransportException("Invalid credentials for '" . $this->fileUrl . "', aborting.", $httpStatus);
$httpStatus);
} }
$this->io->overwriteError(' Authentication required (<info>' . parse_url($this->fileUrl, $this->io->overwriteError(' Authentication required (<info>'.parse_url($this->fileUrl, PHP_URL_HOST).'</info>):');
PHP_URL_HOST) . '</info>):');
$username = $this->io->ask(' Username: '); $username = $this->io->ask(' Username: ');
$password = $this->io->askAndHideAnswer(' Password: '); $password = $this->io->askAndHideAnswer(' Password: ');
$this->io->setAuthentication($this->originUrl, $username, $password); $this->io->setAuthentication($this->originUrl, $username, $password);
@ -706,8 +691,7 @@ class RemoteFilesystem
$urlHost = parse_url($this->fileUrl, PHP_URL_HOST); $urlHost = parse_url($this->fileUrl, PHP_URL_HOST);
// Replace path using hostname as an anchor. // Replace path using hostname as an anchor.
$targetUrl = preg_replace('{^(.+(?://|@)' . preg_quote($urlHost) . '(?::\d+)?)(?:[/\?].*)?$}', $targetUrl = preg_replace('{^(.+(?://|@)'.preg_quote($urlHost).'(?::\d+)?)(?:[/\?].*)?$}', '\1'.$locationHeader, $this->fileUrl);
'\1' . $locationHeader, $this->fileUrl);
} else { } else {
// Relative path; e.g. foo // Relative path; e.g. foo
// This actually differs from PHP which seems to add duplicate slashes. // This actually differs from PHP which seems to add duplicate slashes.
@ -718,8 +702,7 @@ class RemoteFilesystem
if (!empty($targetUrl)) { if (!empty($targetUrl)) {
$this->redirects++; $this->redirects++;
$this->io->writeError(sprintf('Following redirect (%u) %s', $this->redirects, $targetUrl), true, $this->io->writeError(sprintf('Following redirect (%u) %s', $this->redirects, $targetUrl), true, IOInterface::DEBUG);
IOInterface::DEBUG);
$additionalOptions['redirects'] = $this->redirects; $additionalOptions['redirects'] = $this->redirects;
@ -786,6 +769,7 @@ class RemoteFilesystem
/** /**
* CN_match and SNI_server_name are only known once a URL is passed. * CN_match and SNI_server_name are only known once a URL is passed.
* They will be set in the getOptionsForUrl() method which receives a URL. * They will be set in the getOptionsForUrl() method which receives a URL.
*
* cafile or capath can be overridden by passing in those options to constructor. * cafile or capath can be overridden by passing in those options to constructor.
*/ */
$defaults = array( $defaults = array(
@ -847,17 +831,24 @@ class RemoteFilesystem
/** /**
* This method was adapted from Sslurp. * This method was adapted from Sslurp.
* https://github.com/EvanDotPro/Sslurp * https://github.com/EvanDotPro/Sslurp
*
* (c) Evan Coury <me@evancoury.com> * (c) Evan Coury <me@evancoury.com>
*
* For the full copyright and license information, please see below: * For the full copyright and license information, please see below:
*
* Copyright (c) 2013, Evan Coury * Copyright (c) 2013, Evan Coury
* All rights reserved. * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, * * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice, * * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@ -983,13 +974,11 @@ class RemoteFilesystem
)); ));
} }
$context = StreamContextFactory::getContext($url, $options, array( $context = StreamContextFactory::getContext($url, $options, array('options' => array(
'options' => array(
'ssl' => array( 'ssl' => array(
'capture_peer_cert' => true, 'capture_peer_cert' => true,
'verify_peer' => false, // Yes this is fucking insane! But PHP is lame. 'verify_peer' => false, // Yes this is fucking insane! But PHP is lame.
), ), ),
),
)); ));
// Ideally this would just use stream_socket_client() to avoid sending a // Ideally this would just use stream_socket_client() to avoid sending a