Skip to content

Commit 058e605

Browse files
authored
Merge pull request #298 from php-http/redirect-body-handling
document stream_factory
2 parents a708a73 + 5e5248e commit 058e605

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

plugins/redirect.rst

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ Initiate the redirect plugin as follows::
2929
follow redirects instead of going to the right end point directly makes your application slower
3030
and increases the load on both server and client.
3131

32+
.. note::
33+
34+
Depending on the status code, redirecting should change POST/PUT requests to GET requests. This
35+
plugin implements this behaviour - except if you set the ``strict`` option to true, as explained
36+
below. It removes the request body if the method changes, see ``stream_factory`` below.
37+
38+
To understand the exact semantics of which HTTP status changes the method and which not, have a
39+
look at the configuration in the source code of the RedirectPlugin class.
40+
3241
Options
3342
-------
3443

@@ -45,6 +54,16 @@ false, a status of 300 will raise the ``Http\Client\Common\Exception\MultipleRed
4554

4655
``strict``: bool (default: false)
4756

48-
When set to ``true``, 300, 301 and 302 status codes will not modify original request's method and
49-
body on consecutive requests. E. g. POST redirect requests are sent as POST requests instead of
57+
When set to ``true``, 300, 301 and 302 status codes will not modify original request's method and
58+
body on consecutive requests. E. g. POST redirect requests are sent as POST requests instead of
5059
POST redirect requests are sent as GET requests.
60+
61+
``stream_factory``: StreamFactoryInterface (default: auto discovered)
62+
63+
The PSR-17 stream factory is used to create an empty stream for removing the body of the request on
64+
redirection. To keep the body on all redirections, set ``stream_factory`` to null.
65+
The stream factory is discovered if either ``php-http/discovery`` is installed and provides a
66+
factory, or ``nyholm/psr7`` or a new enough version of ``guzzlehttp/psr7`` are installed. If you
67+
only have other implementations, you need to provide the factory in ``stream_factory``.
68+
69+
If no factory is found, the redirect plugin does not remove the body on redirection.

0 commit comments

Comments
 (0)