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

Skip to content

Commit c72a4f0

Browse files
committed
bug #21514 301 status code must drop request method to GET. (jlamur)
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.
2 parents d1e591e + abda966 commit c72a4f0

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

UPGRADE-3.3.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
UPGRADE FROM 3.2 to 3.3
22
=======================
33

4+
BrowserKit
5+
----------
6+
7+
* The request method is dropped from POST to GET when the response
8+
status code is 301.
9+
410
ClassLoader
511
-----------
612

src/Symfony/Component/BrowserKit/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
3.3.0
5+
-----
6+
7+
* [BC BREAK] The request method is dropped from POST to GET when the response
8+
status code is 301.
9+
410
3.2.0
511
-----
612

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ public function followRedirect()
474474

475475
$request = $this->internalRequest;
476476

477-
if (in_array($this->internalResponse->getStatus(), array(302, 303))) {
477+
if (in_array($this->internalResponse->getStatus(), array(301, 302, 303))) {
478478
$method = 'GET';
479479
$files = array();
480480
$content = null;

src/Symfony/Component/BrowserKit/Tests/ClientTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,28 @@ public function testFollowRedirectWithPostMethod()
510510
$this->assertEquals('POST', $client->getRequest()->getMethod(), '->followRedirect() keeps request method');
511511
}
512512

513+
public function testFollowRedirectDropPostMethod()
514+
{
515+
$parameters = array('foo' => 'bar');
516+
$files = array('myfile.foo' => 'baz');
517+
$server = array('X_TEST_FOO' => 'bazbar');
518+
$content = 'foobarbaz';
519+
520+
$client = new TestClient();
521+
522+
foreach (array(301, 302, 303) as $code) {
523+
$client->setNextResponse(new Response('', $code, array('Location' => 'http://www.example.com/redirected')));
524+
$client->request('POST', 'http://www.example.com/foo/foobar', $parameters, $files, $server, $content);
525+
526+
$this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), '->followRedirect() follows a redirect with POST method on response code: '.$code.'.');
527+
$this->assertEmpty($client->getRequest()->getParameters(), '->followRedirect() drops parameters with POST method on response code: '.$code.'.');
528+
$this->assertEmpty($client->getRequest()->getFiles(), '->followRedirect() drops files with POST method on response code: '.$code.'.');
529+
$this->assertArrayHasKey('X_TEST_FOO', $client->getRequest()->getServer(), '->followRedirect() keeps $_SERVER with POST method on response code: '.$code.'.');
530+
$this->assertEmpty($client->getRequest()->getContent(), '->followRedirect() drops content with POST method on response code: '.$code.'.');
531+
$this->assertEquals('GET', $client->getRequest()->getMethod(), '->followRedirect() drops request method to GET on response code: '.$code.'.');
532+
}
533+
}
534+
513535
public function testBack()
514536
{
515537
$client = new TestClient();

0 commit comments

Comments
 (0)