Thanks to visit codestin.com
Credit goes to github.com

Skip to content

301 status code must drop request method to GET. #21514

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
Mar 14, 2017

Conversation

jlamur
Copy link
Contributor

@jlamur jlamur commented Feb 2, 2017

Q A
Branch? master
Bug fix? yes
BC breaks? yes
Tests pass? yes
Fixed tickets #20924
License MIT

RFC 7231 §6.4.2 states that 301 HTTP Code should forward POST requests to the Location URI.

But, it also states that:

For historical reasons, a user agent MAY change the request method from POST to GET for the subsequent request.

This is the behavior implemented in almost all user agents.
However the BrowserKit did forward the method to the subsequent request.

This PR make the BrowserKit change the request method from POST to GET when the response status code is 301.

@jlamur
Copy link
Contributor Author

jlamur commented Feb 5, 2017

@fabpot You authored the original commit (2d34e78) that introduced dropping from POST to GET on 302 and 303 codes only. Could you please confirm that the behaviour was overlooked for the 301 code (as suggested here) and that it was not a deliberate choice, or at least if this PR is a good idea?

@fabpot
Copy link
Member

fabpot commented Feb 16, 2017

I don't remember the reasons why 301 was not included back then. 👍 for changing this in master. ping @symfony/deciders

@@ -507,6 +507,13 @@ public function testFollowRedirectWithPostMethod()
$this->assertArrayHasKey('X_TEST_FOO', $client->getRequest()->getServer(), '->followRedirect() keeps $_SERVER with POST method');
$this->assertEquals($content, $client->getRequest()->getContent(), '->followRedirect() keeps content with POST method');
$this->assertEquals('POST', $client->getRequest()->getMethod(), '->followRedirect() keeps request method');

foreach (array(301, 302, 303) as $code) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be part of a new test. No need to put it here.

@Tobion
Copy link
Contributor

Tobion commented Feb 17, 2017

👍

@xabbuh
Copy link
Member

xabbuh commented Feb 17, 2017

👍 but this should be documented in the upgrade files

@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Feb 18, 2017
@fabpot
Copy link
Member

fabpot commented Mar 1, 2017

@jlamur Can you take the comments into accounts? Moving the new tests to a new method and adding a note in the CHANGELOG/UPGRADE files?

@jlamur
Copy link
Contributor Author

jlamur commented Mar 1, 2017

@fabpot I didn't had enough time to do it, but it will be done this weekend.

@fabpot
Copy link
Member

fabpot commented Mar 6, 2017

@jlamur If you don't have time, I'm sure someone can take over and finish it.

[RFC 7231 §6.4.2](https://tools.ietf.org/html/rfc7231#section-6.4.2) states that 301 HTTP Code should forward POST requests to the Location URI.

But, it also states that:

> For historical reasons, a user agent MAY change the request method from POST to GET for the subsequent request.

This is the behavior implemented in almost all user agents.
However the `BrowserKit` did forward the method to the subsequent request.
@jlamur jlamur force-pushed the fix-301-redirect-drops-get branch from e16159b to abda966 Compare March 7, 2017 13:09
@jlamur
Copy link
Contributor Author

jlamur commented Mar 7, 2017

@fabpot Please let me know if I did something wrong while updating UPGRADE/CHANGELOG files.

@fabpot
Copy link
Member

fabpot commented Mar 14, 2017

Thank you @jlamur.

@fabpot fabpot merged commit abda966 into symfony:master Mar 14, 2017
fabpot added a commit that referenced this pull request Mar 14, 2017
This PR was merged into the 3.3-dev branch.

Discussion
----------

301 status code must drop request method to GET.

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| BC breaks?    | yes
| Tests pass?   | yes
| Fixed tickets | #20924
| License       | MIT

[RFC 7231 §6.4.2](https://tools.ietf.org/html/rfc7231#section-6.4.2) states that 301 HTTP Code should forward POST requests to the Location URI.

But, it also states that:

> For historical reasons, a user agent MAY change the request method from POST to GET for the subsequent request.

This is the behavior implemented in almost all user agents.
However the `BrowserKit` did forward the method to the subsequent request.

This PR make the `BrowserKit` change the request method from POST to GET when the response status code is 301.

Commits
-------

abda966 301 status code must drop request method to GET.
@jlamur jlamur deleted the fix-301-redirect-drops-get branch March 15, 2017 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants