Description
Description
If the initial request method is POST
and the server responds with a Location
header, the RedirectPlugin
is configured to follow the redirect with a GET
request. However, the RedirectPlugin
will resend the body of the initial request. This results in a GET
request with a request body.
Most servers will just ignore the request body of GET
requests. Nevertheless, this causes trouble:
- AWS CloudFront rejects GET requests with request body
- Unnecessary traffic / performance issues
Possible Solution
The RedirectPlugin clones the original request and changes the method to GET
at this point:
client-common/src/Plugin/RedirectPlugin.php
Line 187 in e37e46c
When switching to GET
it should also remove the body.
However, I do not see any way to remove the body easily. One quick & dirty solution that worked for me is to use an empty stream:
$originalRequest = $originalRequest->withBody(GuzzleHttp\Psr7\stream_for(''));