Review main Merged Breaking

90471[!!!][TASK] Streamline PSR-7 response header handling

Tim Weisenberger CR +2 V +2 Normal +206 −21 updated 11/18/25, 19:53

Commit message

This patch standardizes and centralizes PSR-7 response header
processing across Core and Extbase. Previously, Extbase only kept
the last value when a single plugin provided multiple header values,
which made it impossible to emit multiple headers with the same name
such as Set-Cookie. The Core, on the other hand, supported multiple
Set-Cookie headers via an allowlist but merged all other headers with
multiple values into a single comma-separated string. According to
RFC 9110 [1], this is only valid if the header explicitly allows
comma-separated lists.

With this change, multiple header values are preserved if created by
a single extbase plugin, resulting in multiple header lines. A single
value is emitted as a single-line header. This replaces the prior
allowlist and inconsistent behavior with a unified approach.

The structural win with this change is that extbase no longer
triggers header() calls on its own.

The solution does not deal with another detail: Multiple extbase
plugins can not set multiple header lines (e.g. two plugins can not
both set own 'set-cookie'), the last plugin will override the former.
The "last one wins" approach is kept to retain b/w compatibility and
turning this around would break the "i want to overwrite" scenario.
The issue stems from a limitation based on the situation that extbase
plugins return Response objects, which does not allow a distinction
between 'overriding' and 'appending' as such, to notify 'merger' code
in RequestHandler or ContentObjectRenderer on how to act. This is one
of the places where the decision to return PSR-7 Response objects within
extbase bites us: This should be a "content part" or something like that
instead to allow proper merging data in an upper layer. Instances
facing this issue must for now deal with this using a middleware
(probably located *after* "typo3/cms-core/response-propagation" to not
catch the response in case one plugin throws a 3xx/4xx response) that
merges and sets a header compiplation on the Response object.

The new behavior supports additional use cases such as WWW-Authenticate
[2], Link [3] and xkey [4] headers, which are also supported by other
PHP frameworks including Symfony [5], Laravel, CakePHP [6], CodeIgniter
[7] and Yii [8].

[1] https://www.rfc-editor.org/rfc/rfc9110.html
[2] https://developer.mozilla.org/docs/Web/HTTP/Headers/WWW-Authenticate
[3] https://httpwg.org/specs/rfc8288.html
[4] https://github.com/varnish/varnish-modules/blob/master/src/vmod_xkey.vcc
[5] https://github.com/symfony/symfony/blob/e971be71d94871b316d2b11a7ba166d6229af450/src/Symfony/Component/HttpFoundation/Response.php#L335-L360
[6] https://github.com/cakephp/cakephp/blob/e05df58b3a5a1f52d64d3dad8a235337c0d52b12/src/Http/ResponseEmitter.php#L178
[7] https://github.com/codeigniter4/CodeIgniter4/blob/9972ca0fec7e919cbf39157d5c95141baab5cad2/system/HTTP/ResponseTrait.php#L405
[8] https://github.com/yiisoft/yii2/blob/976eac5443b2b6cee8263a4f2bdbf2e6c360102c/framework/web/Response.php#L366

Review

  • Code review CR +2 Done
    • Christian Kuhn +2
    • Garvin Hicking +1
    • Simon Schaufelberger +1
  • Verified V +2 Done
    • Christian Kuhn +2
    • Garvin Hicking +1
    • core-ci +1 CI

Issues 3

Files 9

Review log 5577

Show 3752 earlier messages
  1. Tim Weisenberger uploaded patch set 1 08/21/25, 20:56

  2. core-ci voted on patch set 1 V -1 08/21/25, 21:07 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83717

  3. Tim Weisenberger uploaded patch set 2 V -1 08/23/25, 13:22

  4. core-ci voted on patch set 2 V -1 08/23/25, 13:32 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83795

  5. Tim Weisenberger updated the commit message in patch set 3 V -1 08/23/25, 13:46

  6. core-ci voted on patch set 3 V -1 08/23/25, 13:56 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83796

  7. Tim Weisenberger uploaded patch set 4 V -1 08/23/25, 17:12

  8. core-ci voted on patch set 4 V +1 08/23/25, 17:19 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83802

  9. Tim Weisenberger uploaded patch set 5 V +1 08/23/25, 19:04

  10. core-ci voted on patch set 5 V +1 08/23/25, 19:11 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83803

  11. Tim Weisenberger marked it ready for review 08/23/25, 19:16

  12. Simon Schaufelberger commented on patch set 5 08/25/25, 07:51

    Breaking-107324-StreamlinePSR7ResponseHeaderHandling.rst:20

    please remove all whitespace at the end of the line
  13. Tim Weisenberger uploaded patch set 6 V +1 08/25/25, 20:12

  14. Tim Weisenberger commented on patch set 6 08/25/25, 20:14

    Breaking-107324-StreamlinePSR7ResponseHeaderHandling.rst:20 Reply

    Done
  15. core-ci voted on patch set 6 V +1 08/25/25, 20:20 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83852

  16. Simon Schaufelberger wrote 08/25/25, 21:41

    Removed cc Simon Schaufelberger.
  17. Tim Weisenberger uploaded patch set 7 V +1 11/07/25, 17:31

  18. core-ci voted on patch set 7 V -1 11/07/25, 17:47 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/88662

  19. Tim Weisenberger uploaded patch set 8 V -1 11/07/25, 17:51

  20. core-ci voted on patch set 8 V -1 11/07/25, 18:04 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/88666

  21. Tim Weisenberger uploaded patch set 9 V -1 11/07/25, 21:15

  22. core-ci voted on patch set 9 V +1 11/07/25, 21:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/88672

  23. Garvin Hicking commented on patch set 9 11/07/25, 21:47

    RequestMiddlewares.php:170

  24. Garvin Hicking commented on patch set 9 11/07/25, 21:50

    BlogPostEditingControllerTest.php:120

    Why does this no longer contain a HTTP/200 response, could you explain this to a tired me? 😅
  25. Tim Weisenberger uploaded patch set 10 V +1 11/07/25, 22:11

  26. Simon Schaufelberger commented on patch set 9 11/07/25, 22:16

    Breaking-107324-StreamlinePSR7ResponseHeaderHandling.rst:5

    missing 2 more ==
  27. core-ci voted on patch set 10 V +1 11/07/25, 22:19 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/88673

  28. Tim Weisenberger uploaded patch set 11 V +1 11/07/25, 22:22

  29. core-ci voted on patch set 11 V +1 11/07/25, 22:30 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/88674

  30. Tim Weisenberger commented on patch set 11 11/07/25, 22:35

    Breaking-107324-StreamlinePSR7ResponseHeaderHandling.rst:5 Reply

    Done

    BlogPostEditingControllerTest.php:120 Reply

    Before this patch, the response object did not always contain the real status code, as this was not set in Extbase via the response object but directly via the header function if the status code was > 300 (see change in Bootstrap.php). This means that the behavior in the browser or for the user has not changed, but rather the test now receives the real status code, which is also delivered to the browser.

    RequestMiddlewares.php:170 Reply

    Thanks for the hint, I have adapted the configuration for the middleware in line with the changes.
  31. Simon Schaufelberger commented on patch set 11 11/08/25, 01:07

    to have persistent urls, press y when you are on the url and you will get the commit hash. then this link won't get out of sync.
  32. Tim Weisenberger updated the commit message in patch set 12 V +1 11/08/25, 13:46

  33. core-ci voted on patch set 12 V +1 11/08/25, 13:53 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/88701

  34. Tim Weisenberger commented on patch set 12 11/08/25, 13:55

    Reply

    Good point, done.
  35. Simon Schaufelberger voted on patch set 12 CR +1 11/08/25, 14:31

  36. Sascha Nowak voted on patch set 12 CR +1 V +1 11/08/25, 20:31

  37. Stefan Bürk commented on patch set 12 11/12/25, 10:47

    To be honest I only did a pure code review yet, not testing anything out. I'm not confident with the current code and left some comments stating my brain-provblems for some places. Putting all together, I would say that just from reading the code the promise stated in the commit message and the rest file are not full-filled. This needs deeper testing after some code changes, and I'd say we should add some functional tests to it special having "multiple" extbase plugins on the same page rendered returning response object with response headers and the behaviour - which would make "clear" what really happens even for code-readers only. Can pick up that next week to work an and checking more in depth ....

    Bootstrap.php:176

    > With this change, multiple header values are preserved, resulting in multiple header lines. The code here sets the headers from the extbase plugin response replacing values for already existing header $name, for example of another extbase plugin rendered already on the page (multiple plugins on one page). That means that only the headers for a header $name of the "last" plugin are taken .. and not preserving all values. That counts for "all" header lines, if they support multi header occurances or not. Note: This would remove `Set-Cookie` from prior extbase plugins and only using the cookies from the last plugin setting this header.

    Bootstrap.php:182

    IMO the whole block does not make much sense anways. In practice, status codes >= 300 are not returned by thrown as `PropagateImmediateException` leaving the way back here out as it does not make "sense" to render the full page to just return a "redirect response along with the redirect url header" .... or for example to output file contents (having status code 200 anyway). Not completly sure, but if I remember right we had a StopAction exception thrown here in that case which got removed. We can keep it, but not sure if keeping that here really makes sense, beside it "transports" the statuscode "wished" and returns a not really graspabke state in the end. On top of that ... only the "values" from the last "plugin" would win.

    TypoScriptFrontendController.php:442

    > With this change, multiple header values are preserved, resulting in multiple header lines. This code here sets a header from the internal response-data container as full replacement as singel source of truth for it .. it does not preseves eventually set headers (merging them) ... I think that this should be `$repsonse->withAddedHeader()` here.

    TypoScriptFrontendController.php:447

    Reassigning and creating a object permutatiion just to assign the same body again das not make much sense, or do I miss something essential here ? I'd say this line should be removed making no sense. What do you say ?

    ResponseDataInitialization.php:46

    Thinking about it, I guess I would personally prefere to have this attribute initalization not as a dedicated middleware and instead adding it directly to the `\TYPO3\CMS\Frontend\Middleware\PrepareTypoScriptFrontendRendering`. Beside that, even if it would stay as dedicated middleware we don't need the middlware property state here .. middleware should be called only once. In case of a "subrequest" the dispatching place should incorporate that.

    ResponseData.php:28

    Not sure if we may eventualy simply us the a message or response object directly as data container for the request attribute and avoiding a new additional class with subset of it and additional code to maintain.

    ResponseData.php:72

    The implementation here is quite simple and leaves a lot out which is done in the casual response object, for example: * does not respect the `case-insensitive` nature of header names ... * not realy handling $value, which should be an array .. or in case of a string persisted as an array -> `(string)$value -> $value = [$value]` * this implementation only supports kind of "full set" only and not the "add a header on top of the stack for the header name" See for example: https://github.com/TYPO3/typo3/blob/174e7fdd5db09aa783a5a15bd73156651de8deca/typo3/sysext/core/Classes/Http/Message.php#L187-L280

    ResponseData.php:72

    This implementation leaves a lot out. I assume that has been done either accedentially
  38. Stefan Bürk updated the commit message in patch set 13 CR +1 V +1 11/12/25, 10:47

  39. Stefan Bürk commented on patch set 13 11/12/25, 10:48

    ResponseData.php:28 Reply

    A wait - that does not work due to the immutable nature of these classes :/ :/
  40. core-ci voted on patch set 13 V +1 11/12/25, 10:56 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/89250

  41. Stefan Bürk voted on patch set 13 CR -1 11/12/25, 11:12

  42. Tim Weisenberger uploaded patch set 14 CR -1 V +1 11/12/25, 20:55

  43. core-ci voted on patch set 14 V +1 11/12/25, 21:03 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/89397

  44. Tim Weisenberger commented on patch set 14 11/12/25, 22:08

    Bootstrap.php:176 Reply

    This behavior is intentional. The statement "With this change, multiple header values are preserved, resulting in multiple header lines." does not mean that if a header with the same name is set in several places in the request lifecycle, it will be merged and retained, but rather that if a string is provided, a single header line will be used, and if a string array is provided, all values from this string array will be output as separate header lines and no concatenation with commas is enforced. The implementation in this way also preserves the the behavior of the current implementation, as here (https://github.com/TYPO3/typo3/blob/05ef22fb2209f5d0b6c2210433c52ed04a1b9423/typo3/sysext/extbase/Classes/Core/Bootstrap.php#L175) no value for the third-parameter is set, which results that the a extbase plugin would overwrite the header of the prior extbase plugin, when the header is not send already.

    Bootstrap.php:182 Reply

    When I saw the block for the first time, I had the same thought. For redirect messages (HTTP status code 300-399), further rendering of the page makes no sense and you could use a PropagateResponseException at this point. For HTTP status codes >= 400, it might make sense if the Extbase plugin allows the page to be rendered. For example, rendering an error message with the “frame” of the page. In the end I kept this block so as not to break too many existing implementations unnecessarily. This approach also ensures the continuity of my basic idea for the patch, namely that it is possible to completely manipulate the headers at any point in the entire lifecycle (HTTP request -> AbstractApplication -> HTTP middlewares -> TSFE -> Extbase plugin 1 -> ... Extbase Plugin n -> TSFE -> HTTP middlewares -> AbstractApplication -> HTTP Response), as it is also possible with a PHP framework that consistently uses an PSR-7 request and PSR-7 response object.

    TypoScriptFrontendController.php:447 Reply

    Good point, that line is redundant, it should definitely be removed. A new patch has been pushed.

    ResponseData.php:72 Reply

    The use of the ResponseData attribute outside of the use case implemented so far is not planned, which is why it is marked as internal. In my opinion, another normalization of the headers at this point would be redundant in the current use case, since normalization already takes place in the PSR-7 response from Extbase.
  45. Tim Weisenberger commented on patch set 14 11/12/25, 22:10

    TypoScriptFrontendController.php:447 Reply

    Done
  46. Christian Kuhn uploaded patch set 15 V +1 11/17/25, 14:33

  47. Christian Kuhn commented on patch set 15 11/17/25, 14:34

    rebased for now.
  48. Christian Kuhn commented on patch set 15 11/17/25, 14:40

    Bootstrap.php:175

    it's great getting rid of remaining header() calls!

    ResponseDataInitialization.php:36

    i wonder if we could maybe merge this middleware with another one to safe one additional middleware.
  49. core-ci voted on patch set 15 V +1 11/17/25, 14:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/89946

  50. Christian Kuhn commented on patch set 15 11/17/25, 17:18

    Reply

    Done

    Bootstrap.php:175 Reply

    Done

    Bootstrap.php:176 Reply

    Done

    Bootstrap.php:182 Reply

    yes. we will and should talk about proper 3xx / 4xx handling from within extensions.

    TypoScriptFrontendController.php:442 Reply

    Done

    ResponseDataInitialization.php:36 Reply

    Done

    ResponseDataInitialization.php:46 Reply

    same feeling. we did that.

    ResponseData.php:72 Reply

    yes. our goal is to fix the issue itself for now. we will have to model the entire page-part and http-response segments in a better way in the future. we added some todo with the patch to point that out.
  51. Christian Kuhn uploaded patch set 16 V +1 11/17/25, 17:18

  52. Christian Kuhn voted on patch set 16 CR +1 V +1 11/17/25, 17:19

  1. core-ci voted on patch set 16 V +1 11/17/25, 17:27 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/89953

  2. Christian Kuhn updated the commit message in patch set 17 CR +1 V +1 11/17/25, 17:29

  3. Christian Kuhn voted on patch set 17 CR +1 V +1 11/17/25, 17:29

  4. core-ci voted on patch set 17 V +1 11/17/25, 17:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/89955

  5. Christian Kuhn uploaded patch set 18 CR +1 V +1 11/17/25, 18:06

  6. Christian Kuhn voted on patch set 18 CR +1 V +1 11/17/25, 18:07

  7. Garvin Hicking commented on patch set 18 CR +1 V +1 11/17/25, 18:11

    Thanks a lot for everyone involved, I think the final outcome of this is very lean and a great basis for more streamlining, without behing a burden. Thanks Tim for for staying on it! :-)
  8. core-ci voted on patch set 18 V +1 11/17/25, 18:14 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/89958

  9. Christian Kuhn commented on patch set 18 CR -1 11/17/25, 19:42

    wanna recheck a detail with Tim.
  10. Benni Mack commented on patch set 18 CR -1 11/18/25, 08:27

    must be a [TASK]. Mainly because this "feature" is internal, I'd rather say even it's a bugfix.
  11. Christian Kuhn uploaded patch set 19 CR +1 V +1 11/18/25, 16:59

  12. Christian Kuhn commented on patch set 19 11/18/25, 17:01

    Reply

    thx. done.

    Reply

    there is an additional issue when multiple extbase plugins try to set the same header: last one wins. we can not change that right now, so i elaborated on it in the commit message and roughly in the .rst file.
  13. Christian Kuhn updated the commit message in patch set 20 11/18/25, 17:04

  14. Christian Kuhn updated the commit message in patch set 21 11/18/25, 17:06

  15. Christian Kuhn updated the commit message in patch set 22 11/18/25, 17:07

  16. core-ci voted on patch set 19 V +1 11/18/25, 17:09 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90061

  17. core-ci voted on patch set 20 V +1 11/18/25, 17:14 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90062

  18. core-ci voted on patch set 21 V +1 11/18/25, 17:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90063

  19. core-ci voted on patch set 22 V +1 11/18/25, 17:16 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90064

  20. Garvin Hicking voted on patch set 22 CR +1 V +1 11/18/25, 18:57

  21. Christian Kuhn commented on patch set 22 CR +1 V +1 11/18/25, 19:10

    waiting for a last sign-off from tim.
  22. Tim Weisenberger commented on patch set 22 11/18/25, 19:48

    Reply

    LGTM
  23. Simon Schaufelberger voted on patch set 22 CR +1 11/18/25, 19:51

  24. Christian Kuhn voted on patch set 22 CR +2 V +2 11/18/25, 19:53

  25. Christian Kuhn merged patch set 23 11/18/25, 19:53