Merge branch '2.2' into 2.3
* 2.2: [BrowserKit] fixed method/files/content when redirecting a request [BrowserKit] removed some headers when redirecting a request [BrowserKit] fixed headers when redirecting if history is set to false (refs #8697) [BrowserKit] Pass headers when `followRedirect()` is called Conflicts: src/Symfony/Component/BrowserKit/Client.php src/Symfony/Component/BrowserKit/Tests/ClientTest.php
This commit is contained in:
commit
47b32437e1
@ -492,9 +492,24 @@ abstract class Client
|
||||
}
|
||||
}
|
||||
|
||||
$request = $this->internalRequest;
|
||||
|
||||
if (in_array($this->internalResponse->getStatus(), array(302, 303))) {
|
||||
$method = 'get';
|
||||
$files = array();
|
||||
$content = null;
|
||||
} else {
|
||||
$method = $request->getMethod();
|
||||
$files = $request->getFiles();
|
||||
$content = $request->getContent();
|
||||
}
|
||||
|
||||
$server = $request->getServer();
|
||||
unset($server['HTTP_IF_NONE_MATCH'], $server['HTTP_IF_MODIFIED_SINCE']);
|
||||
|
||||
$this->isMainRequest = false;
|
||||
|
||||
$response = $this->request('get', $this->redirect);
|
||||
$response = $this->request($method, $this->redirect, $request->getParameters(), $files, $server, $content);
|
||||
|
||||
$this->isMainRequest = true;
|
||||
|
||||
|
@ -387,6 +387,11 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
$client->setNextResponse(new Response('', 302, array('Location' => 'http://www.example.com/redirected')));
|
||||
$client->request('GET', 'http://www.example.com/foo/foobar');
|
||||
$this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), '->followRedirect() follows a redirect if any');
|
||||
|
||||
$client->setNextResponse(new Response('', 302, array('Location' => 'http://www.example.com/redirected')));
|
||||
$client->request('POST', 'http://www.example.com/foo/foobar');
|
||||
|
||||
$this->assertEquals('get', $client->getRequest()->getMethod(), '->followRedirect() uses a get for 302');
|
||||
}
|
||||
|
||||
public function testFollowRedirectWithCookies()
|
||||
@ -403,6 +408,33 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array('foo' => 'bar'), $client->getRequest()->getCookies());
|
||||
}
|
||||
|
||||
public function testFollowRedirectWithHeaders()
|
||||
{
|
||||
$headers = array(
|
||||
'HTTP_HOST' => 'www.example.com',
|
||||
'HTTP_USER_AGENT' => 'Symfony2 BrowserKit',
|
||||
'CONTENT_TYPE' => 'application/vnd.custom+xml',
|
||||
'HTTPS' => false,
|
||||
);
|
||||
|
||||
$client = new TestClient();
|
||||
$client->followRedirects(false);
|
||||
$client->setNextResponse(new Response('', 302, array(
|
||||
'Location' => 'http://www.example.com/redirected',
|
||||
)));
|
||||
$client->request('GET', 'http://www.example.com/', array(), array(), array(
|
||||
'CONTENT_TYPE' => 'application/vnd.custom+xml',
|
||||
));
|
||||
|
||||
$this->assertEquals($headers, $client->getRequest()->getServer());
|
||||
|
||||
$client->followRedirect();
|
||||
|
||||
$headers['HTTP_REFERER'] = 'http://www.example.com/';
|
||||
|
||||
$this->assertEquals($headers, $client->getRequest()->getServer());
|
||||
}
|
||||
|
||||
public function testBack()
|
||||
{
|
||||
$client = new TestClient();
|
||||
|
Reference in New Issue
Block a user