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

Conversation

Projects
None yet
4 participants
@akrabat
Member

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

Set status to 302 if Location header set
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

@akrabat akrabat requested review from silentworks and geggleto Nov 18, 2017

@coveralls

This comment has been minimized.

coveralls commented Nov 18, 2017

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

This comment has been minimized.

nickdnk commented Nov 18, 2017

May I suggest using === for comparison:

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

@akrabat akrabat force-pushed the akrabat:fix-redirect-with-200 branch from d2dda78 to afef7ad Nov 18, 2017

@akrabat

This comment has been minimized.

Member

akrabat commented Nov 18, 2017

May I suggest using === for comparison:

Done.

@coveralls

This comment has been minimized.

coveralls commented Nov 18, 2017

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

This comment has been minimized.

coveralls commented Nov 18, 2017

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)) {

This comment has been minimized.

@silentworks

silentworks Nov 18, 2017

Member

Please don't Yoda the codebase. Lets keep it consistent with everywhere else in the codebase.

This comment has been minimized.

@akrabat

akrabat Nov 18, 2017

Member

Done. We should put in a phpcs sniff to prevent it!

@coveralls

This comment has been minimized.

coveralls commented Nov 18, 2017

Coverage Status

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

@silentworks silentworks merged commit c9a768c into slimphp:3.x Nov 18, 2017

2 of 3 checks passed

coverage/coveralls Coverage decreased (-0.04%) to 93.24%
Details
Scrutinizer 1 updated code elements
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment