[BrowserKit] Fixed the handling of parameters when redirecting

POST parameters should not be transmitted as GET parameters after the
redirection when changing the method.
This commit is contained in:
Christophe Coevoet 2013-09-16 18:44:24 +02:00
parent 1fd8652d8a
commit 0e437c5978
2 changed files with 10 additions and 2 deletions

View File

@ -435,10 +435,17 @@ abstract class Client
$content = $request->getContent();
}
if ('get' === strtolower($method)) {
// Don't forward parameters for GET request as it should reach the redirection URI
$parameters = array();
} else {
$parameters = $request->getParameters();
}
$server = $request->getServer();
unset($server['HTTP_IF_NONE_MATCH'], $server['HTTP_IF_MODIFIED_SINCE']);
return $this->request($method, $this->redirect, $request->getParameters(), $files, $server, $content);
return $this->request($method, $this->redirect, $parameters, $files, $server, $content);
}
/**

View File

@ -329,9 +329,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$client = new TestClient();
$client->setNextResponse(new Response('', 302, array('Location' => 'http://www.example.com/redirected')));
$client->request('POST', 'http://www.example.com/foo/foobar');
$client->request('POST', 'http://www.example.com/foo/foobar', array('name' => 'bar'));
$this->assertEquals('get', $client->getRequest()->getMethod(), '->followRedirect() uses a get for 302');
$this->assertEquals(array(), $client->getRequest()->getParameters(), '->followRedirect() does not submit parameters when changing the method');
}
public function testFollowRedirectWithCookies()