Fixed relative redirects for ambiguous paths
This commit is contained in:
parent
6094b5b3a9
commit
5ecc449898
|
@ -303,7 +303,7 @@ abstract class Client
|
|||
|
||||
$uri = $this->getAbsoluteUri($uri);
|
||||
|
||||
if (isset($server['HTTP_HOST'])) {
|
||||
if (!empty($server['HTTP_HOST'])) {
|
||||
$uri = preg_replace('{^(https?\://)'.preg_quote($this->extractHost($uri)).'}', '${1}'.$server['HTTP_HOST'], $uri);
|
||||
}
|
||||
|
||||
|
|
|
@ -399,6 +399,19 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
}
|
||||
|
||||
public function testFollowRelativeRedirect()
|
||||
{
|
||||
$client = new TestClient();
|
||||
$client->setNextResponse(new Response('', 302, array('Location' => '/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 = new TestClient();
|
||||
$client->setNextResponse(new Response('', 302, array('Location' => '/redirected:1234')));
|
||||
$client->request('GET', 'http://www.example.com/foo/foobar');
|
||||
$this->assertEquals('http://www.example.com/redirected:1234', $client->getRequest()->getUri(), '->followRedirect() follows relative urls');
|
||||
}
|
||||
|
||||
public function testFollowRedirectWithMaxRedirects()
|
||||
{
|
||||
$client = new TestClient();
|
||||
|
|
Reference in New Issue