Skip to content

Commit babacf0

Browse files
committed
document configuring plugins on client
1 parent 4c6adad commit babacf0

File tree

2 files changed

+56
-16
lines changed

2 files changed

+56
-16
lines changed

integrations/symfony-bundle.rst

Lines changed: 20 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,22 @@ 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+
-
195+
add_host:
196+
host: "http://localhost:8000"
197+
-
198+
header_defaults:
199+
"X-FOO": bar
200+
-
201+
authentication:
202+
acme_basic:
203+
type: 'basic'
204+
username: 'my_username'
205+
password: 'p4ssw0rd'
188206
189207
190208
Authentication

integrations/symfony-full-configuration.rst

Lines changed: 36 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 mode
7163
formatter: null # Defaults to \Http\Message\Formatter\FullHttpMessageFormatter
7264
captured_body_length: 0
7365
@@ -78,11 +70,41 @@ 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+
- 'httplug.plugin.authentication.my_wsse' # Can reference a globally configured plugin service
81+
- 'httplug.plugin.cache'
82+
-
83+
add_host:
84+
# Host name including protocol and optionally the port number, e.g. https://api.local:8000
85+
host: http://localhost:80 # Required
86+
# Whether to replace the host if request already specifies it
87+
replace: false
88+
-
89+
# Append headers to the request. If the header already exists the value will be appended to the current value.
90+
header_append:
91+
# Keys are the header names, values the header values
92+
headers:
93+
'X-FOO': bar # contrary to default symfony behaviour, hyphens "-" are NOT translated to underscores "_" for the headers.
94+
-
95+
# Set header to default value if it does not exist.
96+
header_defaults:
97+
# Keys are the header names, values the header values
98+
headers:
99+
'X-FOO': bar
100+
-
101+
# Set headers to requests. If the header does not exist it wil be set, if the header already exists it will be replaced.
102+
header_set:
103+
# Keys are the header names, values the header values
104+
headers:
105+
'X-FOO': bar
106+
-
107+
# Remove headers from requests.
108+
header_remove:
109+
# List of header names to remove
110+
headers: ["X-FOO"]

0 commit comments

Comments
 (0)