Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
c4b7a5b8
Commit
c4b7a5b8
authored
Apr 15, 2014
by
catch
Browse files
Issue
#2237681
by damiankloip: Revise Guzzle client configuration and event registration.
parent
f0677c11
Changes
11
Hide whitespace changes
Inline
Side-by-side
core/core.services.yml
View file @
c4b7a5b8
...
...
@@ -159,8 +159,12 @@ services:
path.alias_manager
:
class
:
Drupal\Core\Path\AliasManager
arguments
:
[
'
@path.alias_storage'
,
'
@path.alias_whitelist'
,
'
@language_manager'
]
http_
default_
client
:
http_client
:
class
:
Drupal\Core\Http\Client
http_client_simpletest_subscriber
:
class
:
Drupal\Core\Http\Plugin\SimpletestHttpRequestSubscriber
tags
:
-
{
name
:
http_client_subscriber
}
theme.negotiator
:
class
:
Drupal\Core\Theme\ThemeNegotiator
arguments
:
[
'
@access_check.theme'
,
'
@request_stack'
]
...
...
core/lib/Drupal.php
View file @
c4b7a5b8
...
...
@@ -349,7 +349,7 @@ public static function state() {
* A guzzle http client instance.
*/
public
static
function
httpClient
()
{
return
static
::
$container
->
get
(
'http_
default_
client'
);
return
static
::
$container
->
get
(
'http_client'
);
}
/**
...
...
core/lib/Drupal/Core/CoreServiceProvider.php
View file @
c4b7a5b8
...
...
@@ -26,6 +26,7 @@
use
Drupal\Core\DependencyInjection\Compiler\RegisterBreadcrumbBuilderPass
;
use
Drupal\Core\DependencyInjection\Compiler\RegisterAuthenticationPass
;
use
Drupal\Core\DependencyInjection\Compiler\RegisterTwigExtensionsPass
;
use
Drupal\Core\Http\HttpClientSubscriberPass
;
use
Drupal\Core\Plugin\PluginManagerPass
;
use
Drupal\Core\Theme\ThemeNegotiatorPass
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
...
...
@@ -92,6 +93,8 @@ public function register(ContainerBuilder $container) {
$container
->
addCompilerPass
(
new
RegisterTwigExtensionsPass
());
// Register plugin managers.
$container
->
addCompilerPass
(
new
PluginManagerPass
());
// Register HTTP client subscribers.
$container
->
addCompilerPass
(
new
HttpClientSubscriberPass
());
}
/**
...
...
core/lib/Drupal/Core/Http/Client.php
View file @
c4b7a5b8
...
...
@@ -7,9 +7,10 @@
namespace
Drupal\Core\Http
;
use
Drupal\Core\Http\Plugin\SimpletestHttpRequestSubscriber
;
use
Drupal\Component\Utility\NestedArray
;
use
Drupal\Component\Utility\Settings
;
use
GuzzleHttp\Client
as
GuzzleClient
;
use
GuzzleHttp\Event\SubscriberInterface
;
/**
* Drupal default HTTP client class.
...
...
@@ -21,31 +22,54 @@ class Client extends GuzzleClient {
*/
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'
=>
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
);
// 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
()));
parent
::
__construct
(
$config
);
}
$this
->
getEmitter
()
->
attach
(
new
SimpletestHttpRequestSubscriber
());
/**
* Attaches an event subscriber.
*
* @param \GuzzleHttp\Event\SubscriberInterface $subscriber
* The subscriber to attach.
*
* @see \GuzzleHttp\Event\Emitter::attach()
*/
public
function
attach
(
SubscriberInterface
$subscriber
)
{
$this
->
getEmitter
()
->
attach
(
$subscriber
);
}
/**
* Detaches an event subscriber.
*
* @param \GuzzleHttp\Event\SubscriberInterface $subscriber
* The subscriber to detach.
*
* @see \GuzzleHttp\Event\Emitter::detach()
*/
public
function
detach
(
SubscriberInterface
$subscriber
)
{
$this
->
getEmitter
()
->
detach
(
$subscriber
);
}
}
core/lib/Drupal/Core/Http/HttpClientSubscriberPass.php
0 → 100644
View file @
c4b7a5b8
<?php
/**
* @file
* Contains \Drupal\Core\Http\HttpClientSubscriberPass.
*/
namespace
Drupal\Core\Http
;
use
Symfony\Component\DependencyInjection\ContainerBuilder
;
use
Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface
;
use
Symfony\Component\DependencyInjection\Reference
;
/**
* Registers 'http_client_subscriber' tagged services as http client subscribers.
*/
class
HttpClientSubscriberPass
implements
CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public
function
process
(
ContainerBuilder
$container
)
{
$http_client
=
$container
->
getDefinition
(
'http_client'
);
foreach
(
array_keys
(
$container
->
findTaggedServiceIds
(
'http_client_subscriber'
))
as
$id
)
{
$http_client
->
addMethodCall
(
'attach'
,
array
(
new
Reference
(
$id
)));
}
}
}
core/modules/aggregator/lib/Drupal/aggregator/Form/OpmlFeedAdd.php
View file @
c4b7a5b8
...
...
@@ -52,7 +52,7 @@ public function __construct(FeedStorageInterface $feed_storage, ClientInterface
public
static
function
create
(
ContainerInterface
$container
)
{
return
new
static
(
$container
->
get
(
'entity.manager'
)
->
getStorage
(
'aggregator_feed'
),
$container
->
get
(
'http_
default_
client'
)
$container
->
get
(
'http_client'
)
);
}
...
...
core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/fetcher/DefaultFetcher.php
View file @
c4b7a5b8
...
...
@@ -17,7 +17,7 @@
/**
* Defines a default fetcher implementation.
*
* Uses the http_
default_
client service to download the feed.
* Uses the http_client service to download the feed.
*
* @AggregatorFetcher(
* id = "aggregator",
...
...
@@ -49,7 +49,7 @@ public function __construct(ClientInterface $http_client) {
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
)
{
return
new
static
(
$container
->
get
(
'http_
default_
client'
)
$container
->
get
(
'http_client'
)
);
}
...
...
core/modules/aggregator/tests/modules/aggregator_test/lib/Drupal/aggregator_test/Plugin/aggregator/fetcher/TestFetcher.php
View file @
c4b7a5b8
...
...
@@ -14,7 +14,7 @@
/**
* Defines a test fetcher implementation.
*
* Uses http_
default_
client class to download the feed.
* Uses http_client class to download the feed.
*
* @AggregatorFetcher(
* id = "aggregator_test_fetcher",
...
...
core/modules/hal/hal.services.yml
View file @
c4b7a5b8
...
...
@@ -16,7 +16,7 @@ services:
class
:
Drupal\hal\Normalizer\FileEntityNormalizer
tags
:
-
{
name
:
normalizer
,
priority
:
20
}
arguments
:
[
'
@entity.manager'
,
'
@http_
default_
client'
,
'
@rest.link_manager'
,
'
@module_handler'
]
arguments
:
[
'
@entity.manager'
,
'
@http_client'
,
'
@rest.link_manager'
,
'
@module_handler'
]
serializer.normalizer.entity.hal
:
class
:
Drupal\hal\Normalizer\ContentEntityNormalizer
arguments
:
[
'
@rest.link_manager'
,
'
@entity.manager'
,
'
@module_handler'
]
...
...
core/modules/update/update.services.yml
View file @
c4b7a5b8
...
...
@@ -12,4 +12,4 @@ services:
arguments
:
[
'
@config.factory'
,
'
@queue'
,
'
@update.fetcher'
,
'
@state'
,
'
@private_key'
,
'
@keyvalue'
,
'
@keyvalue.expirable'
]
update.fetcher
:
class
:
Drupal\update\UpdateFetcher
arguments
:
[
'
@config.factory'
,
'
@http_
default_
client'
]
arguments
:
[
'
@config.factory'
,
'
@http_client'
]
core/tests/Drupal/Tests/Core/DrupalTest.php
View file @
c4b7a5b8
...
...
@@ -177,7 +177,7 @@ public function testState() {
* Tests the httpClient() method.
*/
public
function
testHttpClient
()
{
$this
->
setMockContainerService
(
'http_
default_
client'
);
$this
->
setMockContainerService
(
'http_client'
);
$this
->
assertNotNull
(
\
Drupal
::
httpClient
());
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment