merged branch fabpot/browserkit-redirect-22 (PR #8895)

This PR was merged into the 2.2 branch.

Discussion
----------

[BrowserKit] fixed the redirect behavior according to the RFC

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Commits
-------

2d34e78 [BrowserKit] fixed method/files/content when redirecting a request
64e1655 [BrowserKit] removed some headers when redirecting a request
96a4b00 [BrowserKit] fixed headers when redirecting if history is set to false (refs #8697)
This commit is contained in:
Fabien Potencier 2013-08-31 08:10:23 +02:00
commit dc1a539c02
2 changed files with 27 additions and 3 deletions

View File

@ -40,6 +40,9 @@ abstract class Client
protected $redirect;
protected $followRedirects;
private $internalRequest;
private $internalResponse;
/**
* Constructor.
*
@ -250,7 +253,7 @@ abstract class Client
$server['HTTP_HOST'] = parse_url($uri, PHP_URL_HOST);
$server['HTTPS'] = 'https' == parse_url($uri, PHP_URL_SCHEME);
$request = new Request($uri, $method, $parameters, $files, $this->cookieJar->allValues($uri), $server, $content);
$this->internalRequest = $request = new Request($uri, $method, $parameters, $files, $this->cookieJar->allValues($uri), $server, $content);
$this->request = $this->filterRequest($request);
@ -264,7 +267,7 @@ abstract class Client
$this->response = $this->doRequest($this->request);
}
$response = $this->filterResponse($this->response);
$this->internalResponse = $response = $this->filterResponse($this->response);
$this->cookieJar->updateFromResponse($response, $uri);
@ -420,7 +423,22 @@ abstract class Client
throw new \LogicException('The request was not redirected.');
}
return $this->request('get', $this->redirect, array(), array(), $this->history->current()->getServer());
$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']);
return $this->request($method, $this->redirect, $request->getParameters(), $files, $server, $content);
}
/**

View File

@ -326,6 +326,12 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$client->request('GET', 'http://www.example.com/foo/foobar');
$this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), '->followRedirect() automatically follows redirects if followRedirects is true');
$client = new TestClient();
$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()