Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump Guzzle version to 5.3.1 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions libs/GuzzleHttp/Client.php
Expand Up @@ -199,9 +199,12 @@ protected function getDefaultOptions()
'verify' => true
];

// Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set
if ($proxy = getenv('HTTP_PROXY')) {
$settings['proxy']['http'] = $proxy;
// Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set.
// We can only trust the HTTP_PROXY environment variable in a CLI
// process due to the fact that PHP has no reliable mechanism to
// get environment variables that start with "HTTP_".
if (php_sapi_name() == 'cli' && getenv('HTTP_PROXY')) {
$settings['proxy']['http'] = getenv('HTTP_PROXY');
}

if ($proxy = getenv('HTTPS_PROXY')) {
Expand Down
2 changes: 1 addition & 1 deletion libs/GuzzleHttp/ClientInterface.php
Expand Up @@ -11,7 +11,7 @@
*/
interface ClientInterface extends HasEmitterInterface
{
const VERSION = '5.2.0';
const VERSION = '5.3.1';

/**
* Create and return a new {@see RequestInterface} object.
Expand Down
2 changes: 1 addition & 1 deletion libs/GuzzleHttp/Event/AbstractRequestEvent.php
Expand Up @@ -54,7 +54,7 @@ public function getRetryCount()
/**
* @return Transaction
*/
protected function getTransaction()
public function getTransaction()
{
return $this->transaction;
}
Expand Down
5 changes: 2 additions & 3 deletions libs/GuzzleHttp/Event/Emitter.php
Expand Up @@ -43,11 +43,10 @@ public function on($eventName, callable $listener, $priority = 0)
public function once($eventName, callable $listener, $priority = 0)
{
$onceListener = function (
EventInterface $event,
$eventName
EventInterface $event
) use (&$onceListener, $eventName, $listener, $priority) {
$this->removeListener($eventName, $onceListener);
$listener($event, $eventName, $this);
$listener($event, $eventName);
};

$this->on($eventName, $onceListener, $priority);
Expand Down
2 changes: 1 addition & 1 deletion libs/GuzzleHttp/Exception/RequestException.php
Expand Up @@ -34,7 +34,7 @@ public function __construct(
}

/**
* Wrap non-RequesExceptions with a RequestException
* Wrap non-RequestExceptions with a RequestException
*
* @param RequestInterface $request
* @param \Exception $e
Expand Down
2 changes: 1 addition & 1 deletion libs/GuzzleHttp/Message/AbstractMessage.php
Expand Up @@ -107,7 +107,7 @@ public function setHeaders(array $headers)
{
$this->headers = $this->headerNames = [];
foreach ($headers as $key => $value) {
$this->setHeader($key, $value);
$this->addHeader($key, $value);
}
}

Expand Down
2 changes: 1 addition & 1 deletion libs/GuzzleHttp/Message/MessageFactory.php
Expand Up @@ -87,7 +87,7 @@ public function createRequest($method, $url, array $options = [])
unset($options['config']);

// Use a POST body by default
if ($method == 'POST'
if (strtoupper($method) == 'POST'
&& !isset($options['body'])
&& !isset($options['json'])
) {
Expand Down
4 changes: 2 additions & 2 deletions libs/GuzzleHttp/Message/MessageFactoryInterface.php
Expand Up @@ -33,7 +33,7 @@ public function createResponse(
*
* This method accepts an associative array of request options. Below is a
* brief description of each parameter. See
* http://docs.guzzlephp.org/clients.html#request-options for a much more
* http://docs.guzzlephp.org/en/latest/clients.html#request-options for a much more
* in-depth description of each parameter.
*
* - headers: Associative array of headers to add to the request
Expand Down Expand Up @@ -65,7 +65,7 @@ public function createResponse(
* @param array $options Array of options to apply to the request
*
* @return RequestInterface
* @link http://docs.guzzlephp.org/clients.html#request-options
* @link http://docs.guzzlephp.org/en/latest/clients.html#request-options
*/
public function createRequest($method, $url, array $options = []);
}
2 changes: 1 addition & 1 deletion libs/GuzzleHttp/Message/Request.php
Expand Up @@ -51,7 +51,7 @@ public function __construct(

if ($headers) {
foreach ($headers as $key => $value) {
$this->setHeader($key, $value);
$this->addHeader($key, $value);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion libs/GuzzleHttp/Pool.php
Expand Up @@ -328,6 +328,6 @@ private function finishResponse($request, $value, $hash)
$result = $value instanceof ResponseInterface
? ['request' => $request, 'response' => $value, 'error' => null]
: ['request' => $request, 'response' => null, 'error' => $value];
$this->deferred->progress($result);
$this->deferred->notify($result);
}
}
16 changes: 15 additions & 1 deletion libs/GuzzleHttp/Ring/Client/CurlFactory.php
Expand Up @@ -80,6 +80,7 @@ public static function createResponse(
$startLine = explode(' ', array_shift($headers), 3);
$headerList = Core::headersFromLines($headers);
$response['headers'] = $headerList;
$response['version'] = isset($startLine[0]) ? substr($startLine[0], 5) : null;
$response['status'] = isset($startLine[1]) ? (int) $startLine[1] : null;
$response['reason'] = isset($startLine[2]) ? $startLine[2] : null;
$response['body'] = $body;
Expand Down Expand Up @@ -180,7 +181,13 @@ private function getDefaultOptions(array $request, array &$headers)
];

if (isset($request['version'])) {
$options[CURLOPT_HTTP_VERSION] = $request['version'] == 1.1 ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0;
if ($request['version'] == 2.0) {
$options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_2_0;
} else if ($request['version'] == 1.1) {
$options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1;
} else {
$options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0;
}
}

if (defined('CURLOPT_PROTOCOLS')) {
Expand Down Expand Up @@ -388,6 +395,13 @@ private function applyHandlerOptions(array $request, array &$options)
case 'save_to':

if (is_string($value)) {
if (!is_dir(dirname($value))) {
throw new \RuntimeException(sprintf(
'Directory %s does not exist for save_to value of %s',
dirname($value),
$value
));
}
$value = new LazyOpenStream($value, 'w+');
}

Expand Down
24 changes: 21 additions & 3 deletions libs/GuzzleHttp/Ring/Client/CurlHandler.php
Expand Up @@ -57,7 +57,26 @@ public function __destruct()
}
}

/**
* @param array $request
*
* @return CompletedFutureArray
*/
public function __invoke(array $request)
{
return new CompletedFutureArray(
$this->_invokeAsArray($request)
);
}

/**
* @internal
*
* @param array $request
*
* @return array
*/
public function _invokeAsArray(array $request)
{
$factory = $this->factory;

Expand All @@ -71,11 +90,10 @@ public function __invoke(array $request)
$response = ['transfer_stats' => curl_getinfo($h)];
$response['curl']['error'] = curl_error($h);
$response['curl']['errno'] = curl_errno($h);
$response['transfer_stats'] = array_merge($response['transfer_stats'], $response['curl']);
$this->releaseEasyHandle($h);

return new CompletedFutureArray(
CurlFactory::createResponse($this, $request, $response, $hd, $bd)
);
return CurlFactory::createResponse([$this, '_invokeAsArray'], $request, $response, $hd, $bd);
}

private function checkoutEasyHandle()
Expand Down
32 changes: 17 additions & 15 deletions libs/GuzzleHttp/Ring/Client/StreamHandler.php
Expand Up @@ -16,6 +16,7 @@
class StreamHandler
{
private $options;
private $lastHeaders;

public function __construct(array $options = [])
{
Expand All @@ -30,17 +31,20 @@ public function __invoke(array $request)
try {
// Does not support the expect header.
$request = Core::removeHeader($request, 'Expect');
$stream = $this->createStream($url, $request, $headers);
return $this->createResponse($request, $url, $headers, $stream);
$stream = $this->createStream($url, $request);
return $this->createResponse($request, $url, $stream);
} catch (RingException $e) {
return $this->createErrorResponse($url, $e);
}
}

private function createResponse(array $request, $url, array $hdrs, $stream)
private function createResponse(array $request, $url, $stream)
{
$hdrs = $this->lastHeaders;
$this->lastHeaders = null;
$parts = explode(' ', array_shift($hdrs), 3);
$response = [
'version' => substr($parts[0], 5),
'status' => $parts[1],
'reason' => isset($parts[2]) ? $parts[2] : null,
'headers' => Core::headersFromLines($hdrs),
Expand Down Expand Up @@ -176,11 +180,8 @@ private function createResource(callable $callback)
return $resource;
}

private function createStream(
$url,
array $request,
&$http_response_header
) {
private function createStream($url, array $request)
{
static $methods;
if (!$methods) {
$methods = array_flip(get_class_methods(__CLASS__));
Expand Down Expand Up @@ -215,8 +216,7 @@ private function createStream(
$url,
$request,
$options,
$this->createContext($request, $options, $params),
$http_response_header
$this->createContext($request, $options, $params)
);
}

Expand Down Expand Up @@ -285,13 +285,14 @@ private function add_verify(array $request, &$options, $value, &$params)
}
} elseif ($value === false) {
$options['ssl']['verify_peer'] = false;
$options['ssl']['allow_self_signed'] = true;
return;
} else {
throw new RingException('Invalid verify request option');
}

$options['ssl']['verify_peer'] = true;
$options['ssl']['allow_self_signed'] = true;
$options['ssl']['allow_self_signed'] = false;
}

private function add_cert(array $request, &$options, $value, &$params)
Expand Down Expand Up @@ -394,16 +395,17 @@ private function createStreamResource(
$url,
array $request,
array $options,
$context,
&$http_response_header
$context
) {
return $this->createResource(
function () use ($url, &$http_response_header, $context) {
function () use ($url, $context) {
if (false === strpos($url, 'http')) {
trigger_error("URL is invalid: {$url}", E_USER_WARNING);
return null;
}
return fopen($url, 'r', null, $context);
$resource = fopen($url, 'r', null, $context);
$this->lastHeaders = $http_response_header;
return $resource;
},
$request,
$options
Expand Down
2 changes: 0 additions & 2 deletions libs/GuzzleHttp/Ring/Future/MagicFutureTrait.php
@@ -1,8 +1,6 @@
<?php
namespace GuzzleHttp\Ring\Future;

include_once 'BaseFutureTrait.php';

/**
* Implements common future functionality that is triggered when the result
* property is accessed via a magic __get method.
Expand Down
4 changes: 2 additions & 2 deletions libs/GuzzleHttp/Stream/GuzzleStreamWrapper.php
Expand Up @@ -37,7 +37,7 @@ public static function getResource(StreamInterface $stream)
}

return fopen('guzzle://stream', $mode, null, stream_context_create([
'guzzle' => ['stream' => $stream],
'guzzle' => ['stream' => $stream]
]));
}

Expand Down Expand Up @@ -95,7 +95,7 @@ public function stream_stat()
static $modeMap = [
'r' => 33060,
'r+' => 33206,
'w' => 33188,
'w' => 33188
];

return [
Expand Down
1 change: 0 additions & 1 deletion libs/GuzzleHttp/Stream/NullStream.php
@@ -1,6 +1,5 @@
<?php
namespace GuzzleHttp\Stream;

use GuzzleHttp\Stream\Exception\CannotAttachException;

/**
Expand Down
6 changes: 3 additions & 3 deletions libs/GuzzleHttp/Stream/Stream.php
Expand Up @@ -20,14 +20,14 @@ class Stream implements StreamInterface
'r' => true, 'w+' => true, 'r+' => true, 'x+' => true, 'c+' => true,
'rb' => true, 'w+b' => true, 'r+b' => true, 'x+b' => true,
'c+b' => true, 'rt' => true, 'w+t' => true, 'r+t' => true,
'x+t' => true, 'c+t' => true, 'a+' => true,
'x+t' => true, 'c+t' => true, 'a+' => true
],
'write' => [
'w' => true, 'w+' => true, 'rw' => true, 'r+' => true, 'x+' => true,
'c+' => true, 'wb' => true, 'w+b' => true, 'r+b' => true,
'x+b' => true, 'c+b' => true, 'w+t' => true, 'r+t' => true,
'x+t' => true, 'c+t' => true, 'a' => true, 'a+' => true,
],
'x+t' => true, 'c+t' => true, 'a' => true, 'a+' => true
]
];

/**
Expand Down
1 change: 0 additions & 1 deletion libs/GuzzleHttp/Stream/StreamDecoratorTrait.php
@@ -1,6 +1,5 @@
<?php
namespace GuzzleHttp\Stream;

use GuzzleHttp\Stream\Exception\CannotAttachException;

/**
Expand Down
6 changes: 2 additions & 4 deletions libs/GuzzleHttp/Stream/Utils.php
Expand Up @@ -155,23 +155,21 @@ public static function hash(
*
* @param StreamInterface $stream Stream to read from
* @param int $maxLength Maximum buffer length
* @param string $eol Line ending
*
* @return string|bool
*/
public static function readline(StreamInterface $stream, $maxLength = null, $eol = PHP_EOL)
public static function readline(StreamInterface $stream, $maxLength = null)
{
$buffer = '';
$size = 0;
$negEolLen = -strlen($eol);

while (!$stream->eof()) {
if (false === ($byte = $stream->read(1))) {
return $buffer;
}
$buffer .= $byte;
// Break when a new line is found or the max length - 1 is reached
if (++$size == $maxLength || substr($buffer, $negEolLen) === $eol) {
if ($byte == PHP_EOL || ++$size == $maxLength - 1) {
break;
}
}
Expand Down
15 changes: 15 additions & 0 deletions libs/GuzzleHttp/Subscriber/Mock.php
Expand Up @@ -7,6 +7,7 @@
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Message\MessageFactory;
use GuzzleHttp\Message\ResponseInterface;
use GuzzleHttp\Stream\StreamInterface;

/**
* Queues mock responses or exceptions and delivers mock responses or
Expand Down Expand Up @@ -60,6 +61,20 @@ public function onBefore(BeforeEvent $event)
}
}

$saveTo = $event->getRequest()->getConfig()->get('save_to');

if (null !== $saveTo) {
$body = $item->getBody();

if (is_resource($saveTo)) {
fwrite($saveTo, $body);
} elseif (is_string($saveTo)) {
file_put_contents($saveTo, $body);
} elseif ($saveTo instanceof StreamInterface) {
$saveTo->write($body);
}
}

$event->intercept($item);
}

Expand Down