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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions UPGRADE-3.3.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
UPGRADE FROM 3.2 to 3.3
=======================

BrowserKit
----------

* The request method is dropped from POST to GET when the response
status code is 301.

ClassLoader
-----------

Expand Down
6 changes: 6 additions & 0 deletions src/Symfony/Component/BrowserKit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CHANGELOG
=========

3.3.0
-----

* [BC BREAK] The request method is dropped from POST to GET when the response
status code is 301.

3.2.0
-----

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/BrowserKit/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ public function followRedirect()

$request = $this->internalRequest;

if (in_array($this->internalResponse->getStatus(), array(302, 303))) {
if (in_array($this->internalResponse->getStatus(), array(301, 302, 303))) {
$method = 'GET';
$files = array();
$content = null;
Expand Down
22 changes: 22 additions & 0 deletions src/Symfony/Component/BrowserKit/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,28 @@ public function testFollowRedirectWithPostMethod()
$this->assertEquals('POST', $client->getRequest()->getMethod(), '->followRedirect() keeps request method');
}

public function testFollowRedirectDropPostMethod()
{
$parameters = array('foo' => 'bar');
$files = array('myfile.foo' => 'baz');
$server = array('X_TEST_FOO' => 'bazbar');
$content = 'foobarbaz';

$client = new TestClient();

foreach (array(301, 302, 303) as $code) {
$client->setNextResponse(new Response('', $code, array('Location' => 'http://www.example.com/redirected')));
$client->request('POST', 'http://www.example.com/foo/foobar', $parameters, $files, $server, $content);

$this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), '->followRedirect() follows a redirect with POST method on response code: '.$code.'.');
$this->assertEmpty($client->getRequest()->getParameters(), '->followRedirect() drops parameters with POST method on response code: '.$code.'.');
$this->assertEmpty($client->getRequest()->getFiles(), '->followRedirect() drops files with POST method on response code: '.$code.'.');
$this->assertArrayHasKey('X_TEST_FOO', $client->getRequest()->getServer(), '->followRedirect() keeps $_SERVER with POST method on response code: '.$code.'.');
$this->assertEmpty($client->getRequest()->getContent(), '->followRedirect() drops content with POST method on response code: '.$code.'.');
$this->assertEquals('GET', $client->getRequest()->getMethod(), '->followRedirect() drops request method to GET on response code: '.$code.'.');
}
}

public function testBack()
{
$client = new TestClient();
Expand Down