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

Conversation

tiraeth
Copy link

@tiraeth tiraeth commented May 13, 2013

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

Currently, BrowserKit operates incorrectly. It follows "redirect" when Location header is present, but having just the header is not enough to perform redirection. RFC-2616 precisely says that the redirection should be performed only with 30x status codes.

This PR fixes the incorrect behaviour of BrowserKit and make it consist with both the RFC document and with other clients, used for example with Behat.

I've found the issue while testing my application with Behat. I was returning Location header with HTTP 201/Created status code and was surprised that BrowserKit follows the redirection.

This PR is for 2.3 version (master) of Symfony.

@fabpot
Copy link
Member

fabpot commented May 13, 2013

This is definitely "just" a bug. So, we need to fix it in 2.1 (no need to create PRs for other branches).
You need to remove the new argument for followRedirect() as we should not provide workarounds for misbehaving apps.

@@ -328,7 +328,10 @@ public function request($method, $uri, array $parameters = array(), array $files

$this->cookieJar->updateFromResponse($this->internalResponse, $uri);

$this->redirect = $this->internalResponse->getHeader('Location');
$status = $this->internalResponse->getStatus();
$location = $this->internalResponse->getHeader('Location');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should get it only when the status code allows it to avoid useless work

$this->redirect = $this->internalResponse->getHeader('Location');
$status = $this->internalResponse->getStatus();

if ($status >= 300 && $status < 400) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This not 30X but 3XX

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTTP spec says 3xx Redirection but available codes are 30x only and it's a common way of calling redirection status codes - 30x. The conditional, by the way, is a copy-paste from Guzzle.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then maybe the upgrade note should be adjusted?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@fabpot fabpot closed this in da6f190 May 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants