Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ request or you can even start a completely new request. This gives you full cont
history
logger
redirect
request-uri-manipulations
retry
stopwatch
26 changes: 26 additions & 0 deletions plugins/request-uri-manipulations.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Request URI Manipulations
=========================

Request URI manipulations can be done thanks to several plugins:

* ``AddHostPlugin``: Set host, scheme and port. Depending on configuration,
the host is overwritten in every request or only set if not yet defined in the request.
* ``AddPathPlugin``: Prefix the request path with a path, leaving the host information untouched.
* ``BaseUriPlugin``: It's a combination of ``AddHostPlugin`` and ``AddPathPlugin``.

Each plugin use the ``UriInterface`` to build the base request::

use Http\Discovery\HttpClientDiscovery;
use Http\Discovery\UriFactoryDiscovery;
use Http\Client\Common\PluginClient;
use Http\Client\Common\Plugin\BaseUriPlugin;

$plugin = new BaseUriPlugin(UriFactoryDiscovery::find()->createUri('https://domain.com:8000/api'), [
// Always replace the host, even if this one is provided on the sent request. Available for AddHostPlugin.
'replace' => true,
]));

$pluginClient = new PluginClient(
HttpClientDiscovery::find(),
[$plugin]
);