TYPO3-Documentation / TYPO3CMS-Reference-CoreApi

"TYPO3 Explained": Main TYPO3 Core Document: Main classes, Security, TypoScript syntax, Extension API and much more
https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/
22 stars 396 forks source link

Extbase: Example with response in different content type does not work #2525

Open brotkrueml opened 1 year ago

brotkrueml commented 1 year ago

The example on page:

https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ExtensionArchitecture/Extbase/Reference/View/Index.html#response-in-a-different-format

says, it is enough to return a response with a defined content-type header (text/xml). But this is wrong. In page renderer it is overwritten with text/html. As this comes from EXT:blog_example, this is not as easy to adjust. Perhaps it is correctly set in the blog example as in TypoScript the header is set additionally. But this is only the case because the example is defined with a page type.

The solution is to throw a PropagateResponseException($response, 200);. This is also the way to go with downloads, like:

$response = $this->responseFactory->createResponse()
    ->withHeader('Cache-Control', 'private')
    ->withHeader('Content-Disposition', sprintf('attachment; filename="%s"', $filename))
    ->withHeader('Content-Length', (string)filesize($filePath))
    ->withHeader('Content-Type', 'application/pdf')
    ->withBody($this->streamFactory->createStreamFromFile($filePath));

throw new PropagateResponseException($response, 200); 
DavidBruchmann commented 1 year ago

@brotkrueml is this related to v11? If so, is it the same in v12?

brotkrueml commented 1 year ago

Yup, v11 and v12.