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
Set status to 302 if Location header set #2345
Conversation
If the Location header is set, then set to the status code to 302 if it is 200. This ensures that code like this still works: return $response->withHeader('Location', '/login'); However if the status code is set to something other than 200, when we assume intent by the user, so do not override their code. e.g. this code works does not change the status code from 201: return $response->withStatus(201)->withHeader('Location', '/item/1'); Closes #2344
May I suggest using === for comparison:
|
Done. |
Slim/Http/Response.php
Outdated
$clone = clone $this; | ||
$clone->headers->set($name, $value); | ||
|
||
if (200 === $clone->getStatusCode() && 'location' === strtolower($name)) { |
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.
Please don't Yoda the codebase. Lets keep it consistent with everywhere else in the codebase.
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. We should put in a phpcs sniff to prevent it!
If the Location header is set, then set to the status code to 302 if
it is 200. This ensures that code like this still works:
However if the status code is set to something other than 200, when we
assume intent by the user, so do not override their code. e.g. this
code works does not change the status code from 201:
Closes #2344