8000 [BrowserKit] should not follow redirects if status code is not 30x by tiraeth · Pull Request #8025 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[BrowserKit] should not follow redirects if status code is not 30x #8025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
removed new argument from followRedirect
  • Loading branch information
m.chwedziak committed May 13, 2013
commit 6a7e3bd19253682a6f4587056538503b6c6852cd
8 changes: 3 additions & 5 deletions UPGRADE-2.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,11 @@ BrowserKit

* If you are receiving responses with non-30x Status Code and Location header
please be aware that you won't be able to use auto-redirects on these kind
of responses. To force redirection even if the response is not HTT 8000 P 30x,
call `Client::followRedirect(true)` to force-redirect if `Location` header
is present.
of responses.

If you are correctly passing 30x Status Code with Location header, you
don't have to worry about the change.

If you were using responses with Location header and non-30x Status Code,
you have to update your code to forcely follow the redirect with
`Client::followRedirect(true)`.
you have to update your code to manually create another request to URL
grabbed from the Location header.
11 changes: 3 additions & 8 deletions src/Symfony/Component/BrowserKit/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,13 @@ public function reload()
*
* @return Crawler
*
* @param boolean $force Do not check Status Code and follow if Location header present (default: false)
*
* @throws \LogicException If request was not a redirect
*
* @api
*/
public function followRedirect($force = false)
public function followRedirect()
{
if (!$force && empty($this->redirect)) {
if (empty($this->redirect)) {
throw new \LogicException('The request was not redirected.');
}

Expand All @@ -493,10 +491,7 @@ public function followRedirect($force = false)

$this->isMainRequest = false;

$response = $this->request('get', $force
? $this->internalResponse->getHeader('Location')
: $this->redirect
);
$response = $this->request('get', $this->redirect);

$this->isMainRequest = true;

Expand Down
6 changes: 0 additions & 6 deletions src/Symfony/Component/BrowserKit/Tests/ClientTest.php
< 4C7A td id="diff-34d467f504db7607408180b05c728a058dabf8d166e468939175942fee8eb3c5L373" data-line-number="373" class="blob-num blob-num-deletion js-linkable-line-number">
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,6 @@ public function testFollowRedirect()
} catch (\Exception $e) {
$this->assertInstanceof('LogicException', $e, '->followRedirect() throws a \LogicException if the request did not respond with 30x HTTP Code');
}

$client->setNextResponse(new Response('', 201, array('Location' => 'http://www.example.com/redirected')));
$client->request('GET', 'http://www.example.com/foo/foobar');
$client->followRedirect(true);

$this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), '->followRedirect(true) follows a redirect even if HTTP Code differs from 30x');
}

public function testFollowRedirectWithMaxRedirects()
Expand Down
0