Skip to content

RedirectPlugin sends body in GET requests #205

Closed
@josiasmontag

Description

@josiasmontag

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:

$originalRequest = $originalRequest->withMethod($this->redirectCodes[$statusCode]['switch']['to']);

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(''));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions