Review main Merged

71014[BUGFIX] Use HTTP status code from extbase response object

Torben Hansen CR +2 V +2 Easy +6 −0 updated 09/16/21, 10:43

Commit message

The status code of a PSR-7 response object returned by an extbase
action has no influence on the actual status code returned in
frontend context.

With this change, a status code >= 300 from the PSR-7 response
is applied using the PHP header() function.

Review

  • Code review CR +2 Done
    • Benni Mack +2
    • Wouter Wolters +1
    • Christian Kuhn +1
  • Verified V +2 Done
    • Benni Mack +2
    • Christian Kuhn +1
    • core-ci +1 CI

Issues 1

Files 1

Review log 1923

  1. Torben Hansen uploaded patch set 1 09/10/21, 09:37

  2. Mathias Brodala commented on patch set 1 CR -1 09/10/21, 09:46

    Bootstrap.php:203

    If at all this should be done together with all other headers below.
  3. Torben Hansen commented on patch set 1 09/10/21, 09:55

    Bootstrap.php:203 Reply

    The problem is, that all other headers below are key/value pairs and the HTTP status header must be applied as a single string (e.g. "HTTP/1.1 404 Not Found").
  4. core-ci voted on patch set 1 V +1 09/10/21, 09:57 Core CI is happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/16474

  5. Mathias Brodala commented on patch set 1 09/10/21, 09:59

    Bootstrap.php:203 Reply

    I meant that you should group the header() calls below. You can move your code inside of the headers_sent() condition just fine. In fact, you must do this, otherwise you risk sending headers unintentionally.
  6. Christian Kuhn commented on patch set 1 09/10/21, 10:21

    Bootstrap.php:203 Reply

    I agree on the issue itself: Extbase frontend action controllers can nowadays return ResponseInterface and a dev can expect this ends up being transferred to the client. The main issues is that ContentObjectRenderer expects a content string to be returned by a plugin, which is then merged into other content parts of the page, so extbase bootstrap currently sets other response parts on it's own via header(), which is of course ugly. A "proper" solution would be to make ContentObjectRenderer Response aware and have some merging strategy to combine Responses from multiple plugins. This would move the Response handling currently located in Extbase bootstrap to COR / TSFE. That however is more work, and it needs a decision on what happens when multiple plugins return conflicting response headers - last one wins? first one wins? stop rendering when first plugin for instance responds 404 and return that immediately? In the end, the patch as proposed is "the simple solution" and in-line with what is currently provided by the framework. Options are patch details: For instance we could check >=300 as proposed and throw a PropagateResponseException right here, together with a comment that this should be changed when COR is made Response aware. Throwing here would have the advantage that the question "what happens if multiple plugin return conflicting responses" is answered with: First one wins and stops further rendering. This option sounds actually reasonable to me. In case we decide to not throw here (why not?), the header() call should probably be moved to the header() calls below, as Mathias suggested already. What do you think?
  7. Mathias Brodala commented on patch set 1 09/10/21, 10:38

    Bootstrap.php:203 Reply

    The exception suggestion sounds reasonable to me as an interim solution using options currently available. But it sounds like this would be a breaking change for TYPO3v11 and thus need a feature flag.
  8. Torben Hansen uploaded patch set 2 09/10/21, 11:15

  9. Torben Hansen commented on patch set 2 09/10/21, 11:15

    Bootstrap.php:203 Reply

    I fully agree, that in the long run we should have some thing in place that allows COR the handle responses and combine response headers (e.g. based on a configurable ruleset) and/or stop/continue further rendering. Problem with the PropagateResponseException() in `TYPO3\CMS\Extbase\Core\Bootstrap` will be, that it actually stops all other rendering process and just will output the body from the returned response and will not continue rendering as TYPO3 currently does. Also this will be a breaking change as Mathias outlined, so I think this should not go into v11. My current usecase is similar to ext:news error handling (https://github.com/georgringer/news/blob/11/Classes/Controller/NewsBaseController.php#L142), which I adapted to my own extension. In https://github.com/derhansen/sf_event_mgt/blob/typo3_11/Classes/Controller/EventController.php#L281 I render a fluid standalone view, which then should be shown as output of the plugin. For the current code, this is only used to visualize, that the requested resource is not available (e.g. hidden/deleted). But you could also think of e.g. an access control handler in an extbase action, which should show to the user in the current page layout, that e.g. access to a resource is denied together with a 403 status code. I'm also fine to keep current code as it is right now, since setting the status header manually from within my extension works as expected. However, I moved the header calls into the condition as suggested in case this patch will be considered as an intermediate solution.
  10. Mathias Brodala commented on patch set 2 09/10/21, 11:18

    Bootstrap.php:203 Reply

    Done
  11. core-ci voted on patch set 2 V +1 09/10/21, 11:37 Core CI is happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/16475

  12. Christian Kuhn voted on patch set 2 V +1 CR +1 09/13/21, 10:45

  13. Benni Mack commented on patch set 2 CR -1 09/13/21, 10:47

    Bootstrap.php:237

    In general I think it's OK, but I think we'd probably need something like: header('HTTP/' . $response->getProtocolVersion() . ' ' . $response->getStatusCode() . ' ' . $response->getReasonPhrase()); otherwise the example in the ticket (custom reason phrase) would not work
  14. Torben Hansen uploaded patch set 3 09/13/21, 12:08

  15. Torben Hansen commented on patch set 3 09/13/21, 12:10

    Bootstrap.php:237 Reply

    Done
  16. core-ci voted on patch set 3 V -1 09/13/21, 12:15 Core CI is not happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/16647

  17. Torben Hansen uploaded patch set 4 09/13/21, 12:21

  18. core-ci voted on patch set 4 V +1 09/13/21, 12:37 Core CI is happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/16650

  19. Benni Mack voted on patch set 4 V +1 CR +1 09/13/21, 12:58

  20. Christian Kuhn voted on patch set 4 V +1 CR +1 09/13/21, 13:11

  21. Wouter Wolters voted on patch set 4 CR +1 09/13/21, 17:58

  22. Benni Mack voted on patch set 4 V +2 CR +2 09/16/21, 10:43

  23. Benni Mack merged patch set 5 09/16/21, 10:43