Commit e84971c5 authored by webchick's avatar webchick

Issue #2210637 by damiankloip | Crell: Upgrade to Guzzle 4.

parent b1eb0a29
......@@ -3,7 +3,7 @@
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
],
"hash": "5a96c248a0be5c8d138fcbf2a5bf9160",
"hash": "764a98eeaf89d9f52b9c32d343036de0",
"packages": [
{
"name": "doctrine/annotations",
......@@ -457,83 +457,41 @@
"time": "2013-12-30 22:31:37"
},
{
"name": "guzzle/common",
"version": "v3.7.1",
"target-dir": "Guzzle/Common",
"name": "guzzlehttp/guzzle",
"version": "4.0.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/common.git",
"reference": "v3.7.1"
"url": "https://github.com/guzzle/guzzle.git",
"reference": "4063f08ca434efac12bf7a3db0d370b1c451345b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/common/zipball/v3.7.1",
"reference": "v3.7.1",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/4063f08ca434efac12bf7a3db0d370b1c451345b",
"reference": "4063f08ca434efac12bf7a3db0d370b1c451345b",
"shasum": ""
},
"require": {
"php": ">=5.3.2",
"symfony/event-dispatcher": ">=2.1"
"guzzlehttp/streams": "1.*",
"php": ">=5.4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.7-dev"
}
},
"autoload": {
"psr-0": {
"Guzzle\\Common": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Common libraries used by Guzzle",
"homepage": "http://guzzlephp.org/",
"keywords": [
"collection",
"common",
"event",
"exception"
],
"time": "2013-07-05 20:17:54"
},
{
"name": "guzzle/http",
"version": "v3.7.1",
"target-dir": "Guzzle/Http",
"source": {
"type": "git",
"url": "https://github.com/guzzle/http.git",
"reference": "v3.7.1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/http/zipball/v3.7.1",
"reference": "v3.7.1",
"shasum": ""
},
"require": {
"guzzle/common": "self.version",
"guzzle/parser": "self.version",
"guzzle/stream": "self.version",
"php": ">=5.3.2"
},
"suggest": {
"ext-curl": "*"
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "4.*",
"psr/log": "~1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.7-dev"
"dev-master": "4.0.x-dev"
}
},
"autoload": {
"psr-0": {
"Guzzle\\Http": ""
}
"psr-4": {
"GuzzleHttp\\": "src/"
},
"files": [
"src/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
......@@ -546,93 +504,52 @@
"homepage": "https://github.com/mtdowling"
}
],
"description": "HTTP libraries used by Guzzle",
"description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients",
"homepage": "http://guzzlephp.org/",
"keywords": [
"Guzzle",
"client",
"curl",
"framework",
"http",
"http client"
"http client",
"rest",
"web service"
],
"time": "2013-07-02 19:53:26"
"time": "2014-03-29 23:11:36"
},
{
"name": "guzzle/parser",
"version": "v3.7.1",
"target-dir": "Guzzle/Parser",
"source": {
"type": "git",
"url": "https://github.com/guzzle/parser.git",
"reference": "v3.7.1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/parser/zipball/v3.7.1",
"reference": "v3.7.1",
"shasum": ""
},
"require": {
"php": ">=5.3.2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.7-dev"
}
},
"autoload": {
"psr-0": {
"Guzzle\\Parser": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Interchangeable parsers used by Guzzle",
"homepage": "http://guzzlephp.org/",
"keywords": [
"URI Template",
"cookie",
"http",
"message",
"url"
],
"time": "2013-06-11 00:24:07"
},
{
"name": "guzzle/stream",
"version": "v3.7.1",
"target-dir": "Guzzle/Stream",
"name": "guzzlehttp/streams",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/stream.git",
"reference": "v3.7.1"
"url": "https://github.com/guzzle/streams.git",
"reference": "d249beffe5fa5e0da3855974bcc2dd9082069ccf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/stream/zipball/v3.7.1",
"reference": "v3.7.1",
"url": "https://api.github.com/repos/guzzle/streams/zipball/d249beffe5fa5e0da3855974bcc2dd9082069ccf",
"reference": "d249beffe5fa5e0da3855974bcc2dd9082069ccf",
"shasum": ""
},
"require": {
"guzzle/common": "self.version",
"php": ">=5.3.2"
"php": ">=5.4.0"
},
"suggest": {
"guzzle/http": "To convert Guzzle request objects to PHP streams"
"require-dev": {
"phpunit/phpunit": "4.*"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.7-dev"
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-0": {
"Guzzle\\Stream": ""
}
"psr-4": {
"GuzzleHttp\\Stream\\": "src/"
},
"files": [
"src/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
......@@ -645,14 +562,13 @@
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle stream wrapper component",
"description": "Provides a simple abstraction over streams of data (Guzzle 4+)",
"homepage": "http://guzzlephp.org/",
"keywords": [
"Guzzle",
"component",
"stream"
],
"time": "2013-06-27 00:50:43"
"time": "2014-03-25 18:31:28"
},
{
"name": "kriswallsmith/assetic",
......@@ -2143,9 +2059,9 @@
"kriswallsmith/assetic": 15,
"symfony-cmf/routing": 15
},
"platform": [
],
"platform": {
"php": ">=5.4.2"
},
"platform-dev": [
]
......
......@@ -157,19 +157,8 @@ services:
path.alias_manager:
class: Drupal\Core\Path\AliasManager
arguments: ['@path.alias_storage', '@path.alias_whitelist', '@language_manager']
http_client_simpletest_subscriber:
class: Drupal\Core\Http\Plugin\SimpletestHttpRequestSubscriber
http_default_client:
class: Guzzle\Http\Client
# Security consideration: we must not use the certificate authority file
# shipped with Guzzle because it can easily get outdated if a certificate
# authority is hacked. Instead, we rely on the certificate authority file
# provided by the operating system which is more likely going to be updated
# in a timely fashion.
arguments: [null, { curl.CURLOPT_TIMEOUT: 30, curl.CURLOPT_MAXREDIRS: 3, ssl.certificate_authority: system }]
calls:
- [addSubscriber, ['@http_client_simpletest_subscriber']]
- [setUserAgent, ['Drupal (+http://drupal.org/)']]
class: Drupal\Core\Http\Client
theme.negotiator:
class: Drupal\Core\Theme\ThemeNegotiator
arguments: ['@access_check.theme', '@request_stack']
......
......@@ -21,7 +21,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Guzzle\Http\Exception\RequestException;
use GuzzleHttp\Exception\RequestException;
/**
* @file
......@@ -1580,8 +1580,8 @@ function install_retrieve_file($uri, $destination) {
}
try {
$request = \Drupal::httpClient()->get($uri, array('Accept' => 'text/plain'));
$data = $request->send()->getBody(TRUE);
$request = \Drupal::httpClient()->get($uri, array('headers' => array('Accept' => 'text/plain')));
$data = $request->getBody(TRUE);
if (empty($data)) {
return FALSE;
}
......@@ -1603,8 +1603,7 @@ function install_retrieve_file($uri, $destination) {
*/
function install_check_localization_server($uri) {
try {
$request = \Drupal::httpClient()->head($uri);
$request->send();
\Drupal::httpClient()->head($uri);
return TRUE;
}
catch (RequestException $e) {
......
......@@ -345,7 +345,7 @@ public static function state() {
/**
* Returns the default http client.
*
* @return \Guzzle\Http\ClientInterface
* @return \GuzzleHttp\ClientInterface
* A guzzle http client instance.
*/
public static function httpClient() {
......
<?php
/**
* @file
* Contains \Drupal\Core\Http\Client.
*/
namespace Drupal\Core\Http;
use Drupal\Core\Http\Plugin\SimpletestHttpRequestSubscriber;
use Drupal\Component\Utility\NestedArray;
use GuzzleHttp\Client as GuzzleClient;
/**
* Drupal default HTTP client class.
*/
class Client extends GuzzleClient {
/**
* {@inheritdoc}
*/
public function __construct(array $config = []) {
$default_config = array(
'defaults' => array(
'config' => array(
'curl' => array(
CURLOPT_TIMEOUT => 30,
CURLOPT_MAXREDIRS => 3,
),
),
// Security consideration: we must not use the certificate authority
// file shipped with Guzzle because it can easily get outdated if a
// certificate authority is hacked. Instead, we rely on the certificate
// authority file provided by the operating system which is more likely
// going to be updated in a timely fashion. This overrides the default
// path to the pem file bundled with Guzzle.
'verify' => TRUE,
'headers' => array(
'User-Agent' => 'Drupal (+http://drupal.org/)',
),
),
);
$config = NestedArray::mergeDeep($default_config, $config);
parent::__construct($config);
$this->getEmitter()->attach(new SimpletestHttpRequestSubscriber());
}
}
<?php
/**
* @file
* Contains Drupal\Core\Http\Plugin\SimpletestHttpRequestSubscriber
......@@ -6,28 +7,28 @@
namespace Drupal\Core\Http\Plugin;
use Guzzle\Common\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use GuzzleHttp\Event\BeforeEvent;
use GuzzleHttp\Event\SubscriberInterface;
/**
* Subscribe to HTTP requests and override the User-Agent header if the request
* is being dispatched from inside a simpletest.
*/
class SimpletestHttpRequestSubscriber implements EventSubscriberInterface {
class SimpletestHttpRequestSubscriber implements SubscriberInterface {
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return array('request.before_send' => 'onBeforeSendRequest');
public function getEvents() {
return array(
'before' => array('onBeforeSendRequest'),
);
}
/**
* Event callback for request.before_send
* Event callback for the 'before' event
*/
public function onBeforeSendRequest(Event $event) {
public function onBeforeSendRequest(BeforeEvent $event) {
// If the database prefix is being used by SimpleTest to run the tests in a copied
// database then set the user-agent header to the database prefix so that any
// calls to other Drupal pages will run the SimpleTest prefixed database. The
......@@ -35,7 +36,7 @@ public function onBeforeSendRequest(Event $event) {
// same time won't interfere with each other as they would if the database
// prefix were stored statically in a file or database variable.
if ($test_prefix = drupal_valid_test_ua()) {
$event['request']->setHeader('User-Agent', drupal_generate_test_ua($test_prefix));
$event->getRequest()->setHeader('User-Agent', drupal_generate_test_ua($test_prefix));
}
}
}
......@@ -11,9 +11,8 @@
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Form\FormBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Guzzle\Http\Exception\RequestException;
use Guzzle\Http\Exception\BadResponseException;
use Guzzle\Http\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\ClientInterface;
/**
* Imports feeds from OPML.
......@@ -30,7 +29,7 @@ class OpmlFeedAdd extends FormBase {
/**
* The HTTP client to fetch the feed data with.
*
* @var \Guzzle\Http\ClientInterface
* @var \GuzzleHttp\ClientInterface
*/
protected $httpClient;
......@@ -39,7 +38,7 @@ class OpmlFeedAdd extends FormBase {
*
* @param \Drupal\aggregator\FeedStorageInterface $feed_storage
* The feed storage.
* @param \Guzzle\Http\ClientInterface $http_client
* @param \GuzzleHttp\ClientInterface $http_client
* The Guzzle HTTP client.
*/
public function __construct(FeedStorageInterface $feed_storage, ClientInterface $http_client) {
......@@ -121,15 +120,9 @@ public function submitForm(array &$form, array &$form_state) {
else {
// @todo Move this to a fetcher implementation.
try {
$response = $this->httpClient->get($form_state['values']['remote'])->send();
$response = $this->httpClient->get($form_state['values']['remote']);
$data = $response->getBody(TRUE);
}
catch (BadResponseException $e) {
$response = $e->getResponse();
watchdog('aggregator', 'Failed to download OPML file due to "%error".', array('%error' => $response->getStatusCode() . ' ' . $response->getReasonPhrase()), WATCHDOG_WARNING);
drupal_set_message($this->t('Failed to download OPML file due to "%error".', array('%error' => $response->getStatusCode() . ' ' . $response->getReasonPhrase())));
return;
}
catch (RequestException $e) {
watchdog('aggregator', 'Failed to download OPML file due to "%error".', array('%error' => $e->getMessage()), WATCHDOG_WARNING);
drupal_set_message($this->t('Failed to download OPML file due to "%error".', array('%error' => $e->getMessage())));
......
......@@ -10,9 +10,8 @@
use Drupal\aggregator\Plugin\FetcherInterface;
use Drupal\aggregator\FeedInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Guzzle\Http\ClientInterface;
use Guzzle\Http\Exception\BadResponseException;
use Guzzle\Http\Exception\RequestException;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -31,14 +30,14 @@ class DefaultFetcher implements FetcherInterface, ContainerFactoryPluginInterfac
/**
* The HTTP client to fetch the feed data with.
*
* @var \Guzzle\Http\ClientInterface
* @var \GuzzleHttp\ClientInterface
*/
protected $httpClient;
/**
* Constructs a DefaultFetcher object.
*
* @param \Guzzle\Http\ClientInterface $http_client
* @param \GuzzleHttp\ClientInterface $http_client
* A Guzzle client object.
*/
public function __construct(ClientInterface $http_client) {
......@@ -58,7 +57,7 @@ public static function create(ContainerInterface $container, array $configuratio
* {@inheritdoc}
*/
public function fetch(FeedInterface $feed) {
$request = $this->httpClient->get($feed->getUrl());
$request = $this->httpClient->createRequest('GET', $feed->getUrl());
$feed->source_string = FALSE;
// Generate conditional GET headers.
......@@ -70,7 +69,7 @@ public function fetch(FeedInterface $feed) {
}
try {
$response = $request->send();
$response = $this->httpClient->send($request);
// In case of a 304 Not Modified, there is no new content, so return
// FALSE.
......@@ -79,8 +78,8 @@ public function fetch(FeedInterface $feed) {
}
$feed->source_string = $response->getBody(TRUE);
$feed->setEtag($response->getEtag());
$feed->setLastModified(strtotime($response->getLastModified()));
$feed->setEtag($response->getHeader('ETag'));
$feed->setLastModified(strtotime($response->getHeader('Last-Modified')));
$feed->http_headers = $response->getHeaders();
// Update the feed URL in case of a 301 redirect.
......@@ -90,12 +89,6 @@ public function fetch(FeedInterface $feed) {
}
return TRUE;
}
catch (BadResponseException $e) {
$response = $e->getResponse();
watchdog('aggregator', 'The feed from %site seems to be broken because of error "%error".', array('%site' => $feed->label(), '%error' => $response->getStatusCode() . ' ' . $response->getReasonPhrase()), WATCHDOG_WARNING);
drupal_set_message(t('The feed from %site seems to be broken because of error "%error".', array('%site' => $feed->label(), '%error' => $response->getStatusCode() . ' ' . $response->getReasonPhrase())));
return FALSE;
}
catch (RequestException $e) {
watchdog('aggregator', 'The feed from %site seems to be broken because of error "%error".', array('%site' => $feed->label(), '%error' => $e->getMessage()), WATCHDOG_WARNING);
drupal_set_message(t('The feed from %site seems to be broken because of error "%error".', array('%site' => $feed->label(), '%error' => $e->getMessage())));
......
......@@ -10,7 +10,6 @@
use Drupal\aggregator\Plugin\FetcherInterface;
use Drupal\aggregator\Plugin\aggregator\fetcher\DefaultFetcher;
use Drupal\aggregator\FeedInterface;
use Guzzle\Http\Exception\BadResponseException;
/**
* Defines a test fetcher implementation.
......
......@@ -10,7 +10,7 @@
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\rest\LinkManager\LinkManagerInterface;
use Guzzle\Http\ClientInterface;
use GuzzleHttp\ClientInterface;
/**
* Converts the Drupal entity object structure to a HAL array structure.
......@@ -27,7 +27,7 @@ class FileEntityNormalizer extends ContentEntityNormalizer {
/**
* The HTTP client.
*
* @var \Guzzle\Http\ClientInterface
* @var \GuzzleHttp\ClientInterface
*/
protected $httpClient;
......@@ -36,7 +36,7 @@ class FileEntityNormalizer extends ContentEntityNormalizer {
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Guzzle\Http\ClientInterface $http_client
* @param \GuzzleHttp\ClientInterface $http_client
* The HTTP Client.
* @param \Drupal\rest\LinkManager\LinkManagerInterface $link_manager
* The hypermedia link manager.
......@@ -64,9 +64,7 @@ public function normalize($entity, $format = NULL, array $context = array()) {
* {@inheritdoc}
*/
public function denormalize($data, $class, $format = NULL, array $context = array()) {
$file_data = $this->httpClient->get($data['uri'][0]['value'])
->send()
->getBody(TRUE);
$file_data = $this->httpClient->get($data['uri'][0]['value'])->getBody(TRUE);
$path = 'temporary://' . drupal_basename($data['uri'][0]['value']);
$data['uri'] = file_unmanaged_save_data($file_data, $path);
......
......@@ -5,8 +5,7 @@
* Batch process to check the availability of remote or local po files.
*/
use Guzzle\Http\Exception\BadResponseException;
use Guzzle\Http\Exception\RequestException;
use GuzzleHttp\Exception\RequestException;
/**
* Load the common translation API.
......@@ -231,9 +230,7 @@ function locale_translation_batch_fetch_finished($success, $results) {
function locale_translation_http_check($uri) {
try {
$response = \Drupal::httpClient()
->head($uri)
->send();
$response = \Drupal::httpClient()->head($uri);
$result = array();