Bug #79043

PSR-7 non 302 redirects do not work

Added by Benjamin Franzke over 2 years ago. Updated 12 months ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2016-12-20
Due date:
% Done:

100%

TYPO3 Version:
8
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

If a Response object sets a status code other than 302 and adds a Location header,
Core\Bootstrap::sendResponse will always sent a 302 response code, instead of the defined one.

This is because the php header() function implicitly sets the response code to 302 if a location header is sent:
http://php.net/manual/en/function.header.php#refsect1-function.header-parameters

Associated revisions

Revision cce7d774 (diff)
Added by Benjamin Franzke over 2 years ago

[BUGFIX] Fix non-302 redirects for PSR-7 response objects

All redirect status codes (e.g. 201,301,303,307) are incorrectly
sent as 302.

We need to set the response code before setting the Location header,
as a call to header('Location: ...'); sets the response code
implicitly to 302 (unless it has already been set to 201 or 3xx) [1].
By settings the status code/header first, header('Location: ..') will
not change the status code, if the PSR-7 response object contains a
proper redirect status code.

[1] http://php.net/manual/en/function.header.php
The second special case is the "Location:" header.
Not only does it send this header back to the browser, but it also
returns a REDIRECT (302) status code to the browser unless the 201
or a 3xx status code has already been set.

Change-Id: Ifa076e6393c6ed42d93959fe8c3a5b79cee145a4
Fixes: #79043
Releases: master, 7.6
Reviewed-on: https://review.typo3.org/51002
Tested-by: TYPO3com <>
Reviewed-by: Andreas Fernandez <>
Reviewed-by: Philipp Gampe <>
Tested-by: Josef Glatz <>
Reviewed-by: Marco Huber <>
Tested-by: Marco Huber <>
Reviewed-by: Joerg Boesche <>
Reviewed-by: Susanne Moog <>
Tested-by: Susanne Moog <>

Revision 1d645459 (diff)
Added by Benjamin Franzke over 2 years ago

[BUGFIX] Fix non-302 redirects for PSR-7 response objects

All redirect status codes (e.g. 201,301,303,307) are incorrectly
sent as 302.

We need to set the response code before setting the Location header,
as a call to header('Location: ...'); sets the response code
implicitly to 302 (unless it has already been set to 201 or 3xx) [1].
By settings the status code/header first, header('Location: ..') will
not change the status code, if the PSR-7 response object contains a
proper redirect status code.

[1] http://php.net/manual/en/function.header.php
The second special case is the "Location:" header.
Not only does it send this header back to the browser, but it also
returns a REDIRECT (302) status code to the browser unless the 201
or a 3xx status code has already been set.

Change-Id: Ifa076e6393c6ed42d93959fe8c3a5b79cee145a4
Fixes: #79043
Releases: master, 7.6
Reviewed-on: https://review.typo3.org/51815
Tested-by: TYPO3com <>
Reviewed-by: Josef Glatz <>
Tested-by: Josef Glatz <>
Reviewed-by: Morton Jonuschat <>
Tested-by: Morton Jonuschat <>

History

#1 Updated by Gerrit Code Review over 2 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/51002

#2 Updated by Gerrit Code Review over 2 years ago

Patch set 1 for branch TYPO3_7-6 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/51815

#3 Updated by Benjamin Franzke over 2 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

#4 Updated by Benni Mack 12 months ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF