diff --git a/core/core.services.yml b/core/core.services.yml index ef9ccd8..29ac197 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -380,7 +380,7 @@ services: factory: [GuzzleHttp\HandlerStack, create] http_client: class: Drupal\Core\Http\Client - arguments: ['@http_handler_stack'] + arguments: ['@http_handler_stack', '@service_container'] theme.negotiator: class: Drupal\Core\Theme\ThemeNegotiator arguments: ['@access_check.theme'] diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/GuzzleHandlerPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/GuzzleHandlerPass.php index d6dedbf..009e8b2 100644 --- a/core/lib/Drupal/Core/DependencyInjection/Compiler/GuzzleHandlerPass.php +++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/GuzzleHandlerPass.php @@ -17,10 +17,9 @@ class GuzzleHandlerPass implements CompilerPassInterface { * {@inheritdoc} */ public function process(ContainerBuilder $container) { - foreach ($container->findTaggedServiceIds('http_client_handler') as $id => $attributes) { - $container->getDefinition('http_handler_stack') - ->addMethodCall('push', [new Reference($id)]); - } + $service_ids = array_keys($container->findTaggedServiceIds('http_client_handler')); + $container->getDefinition('http_client') + ->addArgument($service_ids); } } diff --git a/core/lib/Drupal/Core/Http/Client.php b/core/lib/Drupal/Core/Http/Client.php index afcd8ce..c6b8da6 100644 --- a/core/lib/Drupal/Core/Http/Client.php +++ b/core/lib/Drupal/Core/Http/Client.php @@ -15,6 +15,7 @@ use GuzzleHttp\Middleware; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Drupal default HTTP client class. @@ -26,7 +27,10 @@ class Client extends GuzzleClient { /** * {@inheritdoc} */ - public function __construct(HandlerStack $stack, array $config = []) { + public function __construct(HandlerStack $stack, ContainerInterface $container, array $service_ids = []) { + foreach ($service_ids as $id) { + $stack->push($container->get($id)->register()); + } $stack->after('allow_redirects', Middleware::mapRequest(function (RequestInterface $request) { $this->effectiveUrl = $request->getUri(); return $request; @@ -52,7 +56,7 @@ public function __construct(HandlerStack $stack, array $config = []) { // The entire config array is merged/configurable to allow Guzzle client // options outside of 'defaults' to be changed, such as 'adapter', or // 'message_factory'. - $config = NestedArray::mergeDeep(array('defaults' => $default_config), $config, Settings::get('http_client_config', array())); + $config = NestedArray::mergeDeep(array('defaults' => $default_config), Settings::get('http_client_config', array())); parent::__construct($config['defaults']); } diff --git a/core/lib/Drupal/Core/Http/StackHandlerRegistrationInterface.php b/core/lib/Drupal/Core/Http/StackHandlerRegistrationInterface.php new file mode 100644 index 0000000..948bf02 --- /dev/null +++ b/core/lib/Drupal/Core/Http/StackHandlerRegistrationInterface.php @@ -0,0 +1,20 @@ +withHeader('User-Agent', drupal_generate_test_ua($test_prefix)); diff --git a/core/modules/aggregator/src/Plugin/aggregator/fetcher/DefaultFetcher.php b/core/modules/aggregator/src/Plugin/aggregator/fetcher/DefaultFetcher.php index 2434b74..80d36bd 100644 --- a/core/modules/aggregator/src/Plugin/aggregator/fetcher/DefaultFetcher.php +++ b/core/modules/aggregator/src/Plugin/aggregator/fetcher/DefaultFetcher.php @@ -92,8 +92,12 @@ public function fetch(FeedInterface $feed) { } $feed->source_string = (string) $response->getBody(); - $feed->setEtag($response->getHeader('ETag')[0]); - $feed->setLastModified(strtotime($response->getHeader('Last-Modified')[0])); + if ($response->hasHeader('ETag')) { + $feed->setEtag($response->getHeader('ETag')[0]); + } + if ($response->hasHeader('Last-Modified')) { + $feed->setLastModified(strtotime($response->getHeader('Last-Modified')[0])); + } $feed->http_headers = $response->getHeaders(); // Update the feed URL in case of a 301 redirect. diff --git a/core/modules/locale/locale.batch.inc b/core/modules/locale/locale.batch.inc index 95333eb..7c1c122 100644 --- a/core/modules/locale/locale.batch.inc +++ b/core/modules/locale/locale.batch.inc @@ -238,9 +238,9 @@ function locale_translation_http_check($uri) { $result = array(); // Return the effective URL if it differs from the requested. -// if ($response->getEffectiveUrl() != $uri) { -// $result['location'] = $response->getEffectiveUrl(); -// } + if ($response->hasHeader('X-Effective-Url') && $response->getHeader('X-Effective-Url')[0] != $uri) { + $result['location'] = $response->getHeader('X-Effective-Url')[0]; + } $result['last_modified'] = $response->hasHeader('Last-Modified') ? strtotime($response->getHeader('Last-Modified')[0]) : 0; return $result;