[BrowserKit] fixed method/files/content when redirecting a request
This commit is contained in:
parent
64e1655164
commit
2d34e78aaf
@ -41,6 +41,7 @@ abstract class Client
|
|||||||
protected $followRedirects;
|
protected $followRedirects;
|
||||||
|
|
||||||
private $internalRequest;
|
private $internalRequest;
|
||||||
|
private $internalResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -266,7 +267,7 @@ abstract class Client
|
|||||||
$this->response = $this->doRequest($this->request);
|
$this->response = $this->doRequest($this->request);
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = $this->filterResponse($this->response);
|
$this->internalResponse = $response = $this->filterResponse($this->response);
|
||||||
|
|
||||||
$this->cookieJar->updateFromResponse($response, $uri);
|
$this->cookieJar->updateFromResponse($response, $uri);
|
||||||
|
|
||||||
@ -422,10 +423,22 @@ abstract class Client
|
|||||||
throw new \LogicException('The request was not redirected.');
|
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']);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -326,6 +326,12 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||||||
$client->request('GET', 'http://www.example.com/foo/foobar');
|
$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');
|
$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()
|
public function testFollowRedirectWithCookies()
|
||||||
|
Reference in New Issue
Block a user