Skip to content

Commit a38beef

Browse files
dbuNyholm
authored andcommitted
document configuring plugins on client (#142)
1 parent f7e64e0 commit a38beef

File tree

2 files changed

+54
-16
lines changed

2 files changed

+54
-16
lines changed

integrations/symfony-bundle.rst

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ The bundle has client factory services that you can use to build your client. If
165165
Plugins
166166
```````
167167

168-
You can configure the clients with plugins. You can choose to use a built in plugin in the ``php-http/plugins`` package or provide a plugin of your own. The order of the specified plugin does matter.
168+
Clients can have plugins. Generic plugins from ``php-http/plugins`` (e.g. retry or redirect) can be configured globally. You can tell the client which of those plugins to use, as well as custom plugins that you configured a service for.
169+
170+
Additionally you can configure any of the ``php-http/plugins`` specifically on a client. For some plugins this is the only place where they can be configured.
171+
The order in which you specify the plugins **does** matter.
169172

170173
.. code-block:: yaml
171174
@@ -184,7 +187,19 @@ You can configure the clients with plugins. You can choose to use a built in plu
184187
clients:
185188
acme:
186189
factory: 'httplug.factory.guzzle6'
187-
plugins: ['acme_plugin', 'httplug.plugin.cache', 'httplug.plugin.retry']
190+
plugins:
191+
- 'acme_plugin'
192+
- 'httplug.plugin.cache'
193+
- 'httplug.plugin.retry'
194+
- add_host:
195+
host: "http://localhost:8000"
196+
- header_defaults:
197+
"X-FOO": bar
198+
- authentication:
199+
acme_basic:
200+
type: 'basic'
201+
username: 'my_username'
202+
password: 'p4ssw0rd'
188203
189204
190205
Authentication

integrations/symfony-full-configuration.rst

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This page shows an example of all configuration values provided by the bundle.
1919
uri_factory: ~
2020
stream_factory: ~
2121
22-
plugins:
22+
plugins: # Global plugin configuration. Plugins need to be explicitly added to clients.
2323
authentication:
2424
my_basic:
2525
type: 'basic'
@@ -36,38 +36,30 @@ This page shows an example of all configuration values provided by the bundle.
3636
type: 'service'
3737
service: 'my_authentication_service'
3838
cache:
39-
enabled: true
4039
cache_pool: 'my_cache_pool'
4140
stream_factory: 'httplug.stream_factory'
4241
config:
4342
default_ttl: 3600
4443
respect_cache_headers: true
4544
cookie:
46-
enabled: true
4745
cookie_jar: my_cookie_jar
4846
decoder:
49-
enabled: true
5047
use_content_encoding: true
5148
history:
52-
enabled: true
5349
journal: my_journal
5450
logger:
55-
enabled: true
5651
logger: 'logger'
5752
formatter: null
5853
redirect:
59-
enabled: true
6054
preserve_header: true
6155
use_default_for_multiple: true
6256
retry:
63-
enabled: true
6457
retry: 1
6558
stopwatch:
66-
enabled: true
6759
stopwatch: 'debug.stopwatch'
6860
69-
toolbar:
70-
enabled: true
61+
profiling:
62+
enabled: true # Defaults to kernel.debug
7163
formatter: null # Defaults to \Http\Message\Formatter\FullHttpMessageFormatter
7264
captured_body_length: 0
7365
@@ -78,11 +70,42 @@ This page shows an example of all configuration values provided by the bundle.
7870
clients:
7971
acme:
8072
factory: 'httplug.factory.guzzle6'
81-
plugins: ['httplug.plugin.authentication.my_wsse', 'httplug.plugin.cache', 'httplug.plugin.retry']
8273
flexible_client: false # Can only be true if http_methods_client is false
8374
http_methods_client: false # Can only be true if flexible_client is false
8475
config:
76+
# Options to the Guzzle 6 constructor
8577
verify: false
8678
timeout: 2
87-
# more options to the Guzzle 6 constructor
88-
79+
plugins:
80+
# Can reference a globally configured plugin service
81+
- 'httplug.plugin.authentication.my_wsse'
82+
# Can configure a plugin customized for this client
83+
- cache:
84+
cache_pool: 'my_other_pool'
85+
config:
86+
default_ttl: 120
87+
# Can configure plugins that can not be configured globally
88+
- add_host:
89+
# Host name including protocol and optionally the port number, e.g. https://api.local:8000
90+
host: http://localhost:80 # Required
91+
# Whether to replace the host if request already specifies it
92+
replace: false
93+
# Append headers to the request. If the header already exists the value will be appended to the current value.
94+
- header_append:
95+
# Keys are the header names, values the header values
96+
headers:
97+
'X-FOO': bar # contrary to default symfony behaviour, hyphens "-" are NOT translated to underscores "_" for the headers.
98+
# Set header to default value if it does not exist.
99+
- header_defaults:
100+
# Keys are the header names, values the header values
101+
headers:
102+
'X-FOO': bar
103+
# Set headers to requests. If the header does not exist it wil be set, if the header already exists it will be replaced.
104+
- header_set:
105+
# Keys are the header names, values the header values
106+
headers:
107+
'X-FOO': bar
108+
# Remove headers from requests.
109+
- header_remove:
110+
# List of header names to remove
111+
headers: ["X-FOO"]

0 commit comments

Comments
 (0)