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

Skip to content

Commit abda966

Browse files
committed
301 status code must drop request method to GET.
[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.
1 parent e98c068 commit abda966

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
@@ -509,6 +509,28 @@ public function testFollowRedirectWithPostMethod()
509509
$this->assertEquals('POST', $client->getRequest()->getMethod(), '->followRedirect() keeps request method');
510510
}
511511

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

0 commit comments

Comments
 (0)