From ea803b05ec25c1c85d3ce96aa91094f986ce9c3e Mon Sep 17 00:00:00 2001 From: Sullivan SENECHAL Date: Tue, 18 Oct 2016 17:36:49 +0200 Subject: [PATCH] Request URI Manipulations --- plugins/index.rst | 1 + plugins/request-uri-manipulations.rst | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 plugins/request-uri-manipulations.rst diff --git a/plugins/index.rst b/plugins/index.rst index d42f129..4a04e70 100644 --- a/plugins/index.rst +++ b/plugins/index.rst @@ -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 diff --git a/plugins/request-uri-manipulations.rst b/plugins/request-uri-manipulations.rst new file mode 100644 index 0000000..76b2b4c --- /dev/null +++ b/plugins/request-uri-manipulations.rst @@ -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] + );