Skip to content
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

Merged
merged 3 commits into from Nov 18, 2017
Merged

Set status to 302 if Location header set #2345

merged 3 commits into from Nov 18, 2017

Conversation

akrabat
Copy link
Member

@akrabat akrabat commented Nov 18, 2017

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

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
@akrabat akrabat added this to the 3.9.1 milestone Nov 18, 2017
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.04%) to 93.24% when pulling c96a4c6 on akrabat:fix-redirect-with-200 into f6884a7 on slimphp:3.x.

@nickdnk
Copy link
Contributor

nickdnk commented Nov 18, 2017

May I suggest using === for comparison:

if (200 === $clone->getStatusCode() && 'location' === strtolower($name)) {
    $clone = $clone->withStatus(302);
}

@akrabat
Copy link
Member Author

akrabat commented Nov 18, 2017

May I suggest using === for comparison:

Done.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.04%) to 93.24% when pulling afef7ad on akrabat:fix-redirect-with-200 into f6884a7 on slimphp:3.x.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.04%) to 93.24% when pulling afef7ad on akrabat:fix-redirect-with-200 into f6884a7 on slimphp:3.x.

$clone = clone $this;
$clone->headers->set($name, $value);

if (200 === $clone->getStatusCode() && 'location' === strtolower($name)) {
Copy link
Member

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.

Copy link
Member Author

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!

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.04%) to 93.24% when pulling 0b40294 on akrabat:fix-redirect-with-200 into f6884a7 on slimphp:3.x.

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.

None yet

4 participants