Commit cdf77e49 authored by alexpott's avatar alexpott

Issue #2317845 by sun | Arla: Upgrade Guzzle to version 4.1.7.

parent 453a4451
......@@ -459,21 +459,21 @@
},
{
"name": "guzzlehttp/guzzle",
"version": "4.1.3",
"version": "4.1.7",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "012b2aecbda4e38f119c19580898685851015fa7"
"reference": "448f2c2076cf0fb756230611491c4f7ecb735a29"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/012b2aecbda4e38f119c19580898685851015fa7",
"reference": "012b2aecbda4e38f119c19580898685851015fa7",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/448f2c2076cf0fb756230611491c4f7ecb735a29",
"reference": "448f2c2076cf0fb756230611491c4f7ecb735a29",
"shasum": ""
},
"require": {
"ext-json": "*",
"guzzlehttp/streams": "~1.3",
"guzzlehttp/streams": "~1.4",
"php": ">=5.4.0"
},
"require-dev": {
......@@ -487,7 +487,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.1.x-dev"
"dev-master": "4.1-dev"
}
},
"autoload": {
......@@ -520,20 +520,20 @@
"rest",
"web service"
],
"time": "2014-07-16 03:01:02"
"time": "2014-08-08 01:30:43"
},
{
"name": "guzzlehttp/streams",
"version": "1.3.0",
"version": "1.5.1",
"source": {
"type": "git",
"url": "https://github.com/guzzle/streams.git",
"reference": "d6aaa91cfdbae86355dd2a168a3ca536755898a2"
"reference": "fb0d1ee29987c2bdc59867bffaade6fc88c2675f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/streams/zipball/d6aaa91cfdbae86355dd2a168a3ca536755898a2",
"reference": "d6aaa91cfdbae86355dd2a168a3ca536755898a2",
"url": "https://api.github.com/repos/guzzle/streams/zipball/fb0d1ee29987c2bdc59867bffaade6fc88c2675f",
"reference": "fb0d1ee29987c2bdc59867bffaade6fc88c2675f",
"shasum": ""
},
"require": {
......@@ -545,7 +545,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
"dev-master": "1.5-dev"
}
},
"autoload": {
......@@ -573,7 +573,7 @@
"Guzzle",
"stream"
],
"time": "2014-07-15 22:02:02"
"time": "2014-08-10 23:57:01"
},
{
"name": "kriswallsmith/assetic",
......@@ -2448,6 +2448,7 @@
"symfony-cmf/routing": 15,
"phpunit/phpunit-mock-objects": 20
},
"prefer-stable": false,
"platform": {
"php": ">=5.4.2"
},
......
......@@ -143,6 +143,8 @@ public function add($prefix, $paths, $prepend = false)
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-0 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
......@@ -202,10 +204,13 @@ public function set($prefix, $paths)
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*/
public function setPsr4($prefix, $paths) {
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
......
......@@ -23,9 +23,6 @@ public static function getLoader()
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInitDrupal8', 'loadClassLoader'));
$vendorDir = dirname(__DIR__);
$baseDir = dirname(dirname($vendorDir));
$includePaths = require __DIR__ . '/include_paths.php';
array_push($includePaths, get_include_path());
set_include_path(join(PATH_SEPARATOR, $includePaths));
......
......@@ -2301,18 +2301,109 @@
]
},
{
"name": "guzzlehttp/streams",
"version": "1.3.0",
"name": "symfony/serializer",
"version": "v2.5.2",
"version_normalized": "2.5.2.0",
"target-dir": "Symfony/Component/Serializer",
"source": {
"type": "git",
"url": "https://github.com/symfony/Serializer.git",
"reference": "33185b290310ab1fd8283fb8ed2a434cdb88b9b9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Serializer/zipball/33185b290310ab1fd8283fb8ed2a434cdb88b9b9",
"reference": "33185b290310ab1fd8283fb8ed2a434cdb88b9b9",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"time": "2014-07-09 09:05:48",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.5-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Symfony\\Component\\Serializer\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com",
"homepage": "http://fabien.potencier.org",
"role": "Lead Developer"
},
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
}
],
"description": "Symfony Serializer Component",
"homepage": "http://symfony.com"
},
{
"name": "mikey179/vfsStream",
"version": "v1.3.0",
"version_normalized": "1.3.0.0",
"source": {
"type": "git",
"url": "https://github.com/mikey179/vfsStream.git",
"reference": "8571f349567e02af1b7efc0fc4e3a4a1c98e664e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mikey179/vfsStream/zipball/8571f349567e02af1b7efc0fc4e3a4a1c98e664e",
"reference": "8571f349567e02af1b7efc0fc4e3a4a1c98e664e",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "~4.1"
},
"time": "2014-07-21 20:15:54",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.3.x-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"org\\bovigo\\vfs\\": "src/main/php"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD"
],
"homepage": "http://vfs.bovigo.org/"
},
{
"name": "guzzlehttp/streams",
"version": "1.5.1",
"version_normalized": "1.5.1.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/streams.git",
"reference": "d6aaa91cfdbae86355dd2a168a3ca536755898a2"
"reference": "fb0d1ee29987c2bdc59867bffaade6fc88c2675f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/streams/zipball/d6aaa91cfdbae86355dd2a168a3ca536755898a2",
"reference": "d6aaa91cfdbae86355dd2a168a3ca536755898a2",
"url": "https://api.github.com/repos/guzzle/streams/zipball/fb0d1ee29987c2bdc59867bffaade6fc88c2675f",
"reference": "fb0d1ee29987c2bdc59867bffaade6fc88c2675f",
"shasum": ""
},
"require": {
......@@ -2321,11 +2412,11 @@
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"time": "2014-07-15 22:02:02",
"time": "2014-08-10 23:57:01",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
"dev-master": "1.5-dev"
}
},
"installation-source": "dist",
......@@ -2357,22 +2448,22 @@
},
{
"name": "guzzlehttp/guzzle",
"version": "4.1.3",
"version_normalized": "4.1.3.0",
"version": "4.1.7",
"version_normalized": "4.1.7.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "012b2aecbda4e38f119c19580898685851015fa7"
"reference": "448f2c2076cf0fb756230611491c4f7ecb735a29"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/012b2aecbda4e38f119c19580898685851015fa7",
"reference": "012b2aecbda4e38f119c19580898685851015fa7",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/448f2c2076cf0fb756230611491c4f7ecb735a29",
"reference": "448f2c2076cf0fb756230611491c4f7ecb735a29",
"shasum": ""
},
"require": {
"ext-json": "*",
"guzzlehttp/streams": "~1.3",
"guzzlehttp/streams": "~1.4",
"php": ">=5.4.0"
},
"require-dev": {
......@@ -2383,11 +2474,11 @@
"suggest": {
"ext-curl": "Guzzle will use specific adapters if cURL is present"
},
"time": "2014-07-16 03:01:02",
"time": "2014-08-08 01:30:43",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.1.x-dev"
"dev-master": "4.1-dev"
}
},
"installation-source": "dist",
......@@ -2421,96 +2512,5 @@
"rest",
"web service"
]
},
{
"name": "symfony/serializer",
"version": "v2.5.2",
"version_normalized": "2.5.2.0",
"target-dir": "Symfony/Component/Serializer",
"source": {
"type": "git",
"url": "https://github.com/symfony/Serializer.git",
"reference": "33185b290310ab1fd8283fb8ed2a434cdb88b9b9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Serializer/zipball/33185b290310ab1fd8283fb8ed2a434cdb88b9b9",
"reference": "33185b290310ab1fd8283fb8ed2a434cdb88b9b9",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"time": "2014-07-09 09:05:48",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.5-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Symfony\\Component\\Serializer\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com",
"homepage": "http://fabien.potencier.org",
"role": "Lead Developer"
},
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
}
],
"description": "Symfony Serializer Component",
"homepage": "http://symfony.com"
},
{
"name": "mikey179/vfsStream",
"version": "v1.3.0",
"version_normalized": "1.3.0.0",
"source": {
"type": "git",
"url": "https://github.com/mikey179/vfsStream.git",
"reference": "8571f349567e02af1b7efc0fc4e3a4a1c98e664e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mikey179/vfsStream/zipball/8571f349567e02af1b7efc0fc4e3a4a1c98e664e",
"reference": "8571f349567e02af1b7efc0fc4e3a4a1c98e664e",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "~4.1"
},
"time": "2014-07-21 20:15:54",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.3.x-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"org\\bovigo\\vfs\\": "src/main/php"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD"
],
"homepage": "http://vfs.bovigo.org/"
}
]
......@@ -10,7 +10,8 @@ before_script:
- curl --version
- pear config-set php_ini ~/.phpenv/versions/`php -r 'echo phpversion();'`/etc/php.ini || echo 'Error modifying PEAR'
- pecl install uri_template || echo 'Error installing uri_template'
- composer install
- composer self-update
- composer install --no-interaction --prefer-source --dev
- ~/.nvm/nvm.sh install v0.6.14
- ~/.nvm/nvm.sh run v0.6.14
......
CHANGELOG
=========
4.1.7 (2014-08-07)
------------------
* Fixed an error in the HistoryPlugin that caused the same request and response
to be logged multiple times when an HTTP protocol error occurs.
* Ensuring that cURL does not add a default Content-Type when no Content-Type
has been supplied by the user. This prevents the adapter layer from modifying
the request that is sent over the wire after any listeners may have already
put the request in a desired state (e.g., signed the request).
* Throwing an exception when you attempt to send requests that have the
"stream" set to true in parallel using the MultiAdapter.
* Only calling curl_multi_select when there are active cURL handles. This was
previously changed and caused performance problems on some systems due to PHP
always selecting until the maximum select timeout.
* Fixed a bug where multipart/form-data POST fields were not correctly
aggregated (e.g., values with "&").
4.1.6 (2014-08-03)
------------------
* Added helper methods to make it easier to represent messages as strings,
including getting the start line and getting headers as a string.
4.1.5 (2014-08-02)
------------------
* Automatically retrying cURL "Connection died, retrying a fresh connect"
errors when possible.
* cURL implementation cleanup
* Allowing multiple event subscriber listeners to be registered per event by
passing an array of arrays of listener configuration.
4.1.4 (2014-07-22)
------------------
* Fixed a bug that caused multi-part POST requests with more than one field to
serialize incorrectly.
* Paths can now be set to "0"
* `ResponseInterface::xml` now accepts a `libxml_options` option and added a
missing default argument that was required when parsing XML response bodies.
* A `save_to` stream is now created lazily, which means that files are not
created on disk unless a request succeeds.
4.1.3 (2014-07-15)
------------------
......
......@@ -17,7 +17,7 @@
"require": {
"php": ">=5.4.0",
"ext-json": "*",
"guzzlehttp/streams": "~1.3"
"guzzlehttp/streams": "~1.4"
},
"suggest": {
......@@ -43,7 +43,7 @@
"extra": {
"branch-alias": {
"dev-master": "4.1.x-dev"
"dev-master": "4.1-dev"
}
}
}
......@@ -297,7 +297,7 @@ immeditaley and prevent subsequent requests from being sent.
use GuzzleHttp\Event\ErrorEvent;
$client->sendAll($requests, [
'error' => function (ErrorEvent $event) use (&$errors) {
'error' => function (ErrorEvent $event) {
throw $event->getException();
}
]);
......
......@@ -184,7 +184,7 @@ priority of the listener (as shown in the ``before`` listener in the example).
.. code-block:: php
use GuzzleHttp\Event\EventEmitterInterface;
use GuzzleHttp\Event\EmitterInterface;
use GuzzleHttp\Event\SubscriberInterface;
use GuzzleHttp\Event\BeforeEvent;
use GuzzleHttp\Event\CompleteEvent;
......@@ -194,8 +194,11 @@ priority of the listener (as shown in the ``before`` listener in the example).
public function getEvents()
{
return [
'before' => ['onBefore', 100], // Provide name and optional priority
'complete' => ['onComplete']
// Provide name and optional priority
'before' => ['onBefore', 100],
'complete' => ['onComplete'],
// You can pass a list of listeners with different priorities
'error' => [['beforeError', 'first'], ['afterError', 'last]]
];
}
......
......@@ -50,7 +50,7 @@ then you'll need to use a ``GuzzleHttp\ClientInterface`` object.
use GuzzleHttp\Client;
$client = new Client();
$response = $client->get('https://github.com/timeline.json');
$response = $client->get('http://httpbin.org/get');
// You can use the same methods you saw in the procedural API
$response = $client->delete('http://httpbin.org/delete');
......@@ -120,9 +120,9 @@ response.
.. code-block:: php
$response = $client->get('https://github.com/timeline.json');
$response = $client->get('http://httpbin.org/get');
$json = $response->json();
var_dump($json[0]['repository']);
var_dump($json[0]['origin']);
Guzzle internally uses PHP's ``json_decode()`` function to parse responses. If
Guzzle is unable to parse the JSON response body, then a
......
......@@ -59,6 +59,16 @@ public function findTransaction($handle)
throw new AdapterException('No curl handle was found');
}
/**
* Returns true if there are any active requests.
*
* @return bool
*/
public function isActive()
{
return count($this->handles) > 0;
}
/**
* Returns true if there are any remaining pending transactions
*
......@@ -143,16 +153,15 @@ public function removeTransaction(TransactionInterface $transaction)
}
$handle = $this->handles[$transaction];
$this->handles->detach($transaction);
$info = curl_getinfo($handle);
$code = curl_multi_remove_handle($this->multi, $handle);
if ($code != CURLM_OK) {
curl_close($handle);
if ($code !== CURLM_OK) {
MultiAdapter::throwMultiError($code);
}
$info = curl_getinfo($handle);
curl_close($handle);
unset($this->handles[$transaction]);
return $info;
}
}
......@@ -91,6 +91,11 @@ protected function getDefaultOptions(
$this->removeHeader('Accept-Encoding', $options);
}
// cURL sometimes adds a content-type by default. Prevent this.
if (!$request->hasHeader('Content-Type')) {
$options[CURLOPT_HTTPHEADER][] = 'Content-Type:';
}
return $options;
}
......@@ -273,6 +278,18 @@ private function add_ssl_key(
$options[CURLOPT_SSLKEY] = $value;
}
private function add_stream()
{
throw new AdapterException('cURL adapters do not support the "stream"'
. ' request option. This error is typically encountered when trying'
. ' to send requests with the "stream" option set to true in '
. ' parallel. You will either need to send these one at a time or'
. ' implement a custom ParallelAdapterInterface that supports'
. ' sending these types of requests in parallel. This error can'
. ' also occur if the StreamAdapter is not available on your'
. ' system (e.g., allow_url_fopen is disabled in your php.ini).');
}
private function add_save_to(
RequestInterface $request,
RequestMediator $mediator,
......@@ -280,7 +297,7 @@ private function add_save_to(
$value
) {
$mediator->setResponseBody(is_string($value)
? Stream\create(fopen($value, 'w'))
? new Stream\LazyOpenStream($value, 'w')
: Stream\create($value));
}
......
......@@ -128,20 +128,25 @@ private function perform(BatchContext $context)
$multi = $context->getMultiHandle();
do {
while (($mrc = curl_multi_exec($multi, $active)) == CURLM_CALL_MULTI_PERFORM);
if ($mrc != CURLM_OK && $mrc != CURLM_CALL_MULTI_PERFORM) {
do {
$mrc = curl_multi_exec($multi, $active);
} while ($mrc === CURLM_CALL_MULTI_PERFORM);
if ($mrc != CURLM_OK) {
self::throwMultiError($mrc);
}
// Need to check if there are pending transactions before processing
// them so that we don't bail from the loop too early.
$pending = $context->hasPending();
$this->processMessages($context);
if ($active && curl_multi_select($multi, $this->selectTimeout) === -1) {
if ($active &&
curl_multi_select($multi, $this->selectTimeout) === -1
) {
// Perform a usleep if a select returns -1.
// See: https://bugs.php.net/bug.php?id=61141
usleep(250);
}
} while ($active || $pending);
} while ($context->isActive() || $active);
$this->releaseMultiHandle($multi);
}
......@@ -168,7 +173,9 @@ private function processResponse(
$info = $context->removeTransaction($transaction);
try {
if (!$this->isCurlException($transaction, $curl, $context, $info)) {
if (!$this->isCurlException($transaction, $curl, $context, $info) &&
$this->validateResponseWasSet($transaction, $context)
) {
RequestEvents::emitComplete($transaction, $info);
}
} catch (RequestException $e) {
......@@ -281,4 +288,75 @@ private function releaseMultiHandle($handle)
unset($this->multiHandles[$id], $this->multiOwned[$id]);
}
}
/**
* This function ensures that a response was set on a transaction. If one
* was not set, then the request is retried if possible. This error
* typically means you are sending a payload, curl encountered a
* "Connection died, retrying a fresh connect" error, tried to rewind the
* stream, and then encountered a "necessary data rewind wasn't possible"
* error, causing the request to be sent through curl_multi_info_read()
* without an error status.
*
* @param TransactionInterface $transaction
* @param BatchContext $context
*
* @return bool Returns true if it's OK, and false if it failed.
* @throws \GuzzleHttp\Exception\RequestException If it failed and cannot
* recover.
*/
private function validateResponseWasSet(
TransactionInterface $transaction,
BatchContext $context
) {
if ($transaction->getResponse()) {
return true;
}
$body = $transaction->getRequest()->getBody();
if (!$body) {
// This is weird and should probably never happen.
RequestEvents::emitError(
$transaction,
new RequestException(
'No response was received for a request with no body. This'
. ' could mean that you are saturating your network.',
$transaction->getRequest()
)
);
} elseif (!$body->isSeekable() || !$body->seek(0)) {
// Nothing we can do with this. Sorry!
RequestEvents::emitError(
$transaction,
new RequestException(
'The connection was unexpectedly closed. The request would'
. ' have been retried, but attempting to rewind the'
. ' request body failed. Consider wrapping your request'
. ' body in a CachingStream decorator to work around this'
. ' issue if necessary.',
$transaction->getRequest()
)
);
} else {
$this->retryFailedConnection($transaction, $context);
}
return false;
}
private function retryFailedConnection(
TransactionInterface $transaction,