Skip to content

Commit ea803b0

Browse files
committed
Request URI Manipulations
1 parent a484ddb commit ea803b0

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

plugins/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ request or you can even start a completely new request. This gives you full cont
2020
history
2121
logger
2222
redirect
23+
request-uri-manipulations
2324
retry
2425
stopwatch

plugins/request-uri-manipulations.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Request URI Manipulations
2+
=========================
3+
4+
Request URI manipulations can be done thanks to several plugins:
5+
6+
* ``AddHostPlugin``: Set host, scheme and port. Depending on configuration,
7+
the host is overwritten in every request or only set if not yet defined in the request.
8+
* ``AddPathPlugin``: Prefix the request path with a path, leaving the host information untouched.
9+
* ``BaseUriPlugin``: It's a combination of ``AddHostPlugin`` and ``AddPathPlugin``.
10+
11+
Each plugin use the ``UriInterface`` to build the base request::
12+
13+
use Http\Discovery\HttpClientDiscovery;
14+
use Http\Discovery\UriFactoryDiscovery;
15+
use Http\Client\Common\PluginClient;
16+
use Http\Client\Common\Plugin\BaseUriPlugin;
17+
18+
$plugin = new BaseUriPlugin(UriFactoryDiscovery::find()->createUri('https://domain.com:8000/api'), [
19+
// Always replace the host, even if this one is provided on the sent request. Available for AddHostPlugin.
20+
'replace' => true,
21+
]));
22+
23+
$pluginClient = new PluginClient(
24+
HttpClientDiscovery::find(),
25+
[$plugin]
26+
);

0 commit comments

Comments
 (0)