-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
This is definitely "just" a bug. So, we need to fix it in 2.1 (no need to create PRs for other branches). |
@@ -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'); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
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 with30x
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 withHTTP 201/Created
status code and was surprised that BrowserKit follows the redirection.This PR is for 2.3 version (master) of Symfony.