Skip to content

Update request-uri-manipulations.rst #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2019
Merged
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
13 changes: 12 additions & 1 deletion plugins/request-uri-manipulations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Request URI manipulations can be done thanks to several plugins:
* ``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::
Each plugin uses the ``UriInterface`` to build the base request::

use Http\Discovery\HttpClientDiscovery;
use Http\Discovery\UriFactoryDiscovery;
Expand All @@ -24,3 +24,14 @@ Each plugin use the ``UriInterface`` to build the base request::
HttpClientDiscovery::find(),
[$plugin]
);

The ``AddPathPlugin`` will check if the path prefix is already present on the
URI. This will break for the edge case when the prefix is repeated. For example,
if ``https://example.com/api/api/foo`` is a valid URI on the server and the
configured prefix is ``/api``, the request to ``/api/foo`` is not rewritten.

For further details, please see the phpdoc on the ``AddPathPlugin`` source code.

No solution fits all use cases. This implementation works fine for the common
use cases. If you have a specific situation where this is not the right thing,
you can build a custom plugin that does exactly what you need.