[BrowserKit] fixed method/files/content when redirecting a request

This commit is contained in:
Fabien Potencier 2013-08-30 20:43:05 +02:00
parent 64e1655164
commit 2d34e78aaf
2 changed files with 22 additions and 3 deletions

View File

@ -41,6 +41,7 @@ abstract class Client
protected $followRedirects;
private $internalRequest;
private $internalResponse;
/**
* Constructor.
@ -266,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);
@ -422,10 +423,22 @@ abstract class Client
throw new \LogicException('The request was not redirected.');
}
$server = $this->internalRequest->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('get', $this->redirect, array(), array(), $server);
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()