Project

General

Profile

Actions

Bug #99534

closed

Content-Type forced to text/html when streaming file

Added by Gregor Hermens over 1 year ago. Updated about 2 months ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2023-01-13
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
11
PHP Version:
8.2
Tags:
Complexity:
Is Regression:
Sprint Focus:
On Location Sprint

Description

I have an extbase action that streams a file like

/** @var \TYPO3\CMS\Core\Resource\FileReference $file */
$originalFile = $file->getOriginalResource()->getOriginalFile();
return $originalFile->getStorage()->streamFile(
  $originalFile,
  false
);

The target page is stripped down to the minimum:

config >
config {
    disableAllHeaderCode = 1
    disableBodyTag = 1
    disableCharsetHeader = 1
    disableLanguageHeader = 1
    doctype = none
    admPanel = 0
    debug = 0
    xhtml_cleaning = none
    disablePrefixComment = 1
    no_cache = 1
}

page >
page = PAGE
page {
    10 = COA_INT
    10 {
        10 < tt_content.list.20.myext_downloadstream
    }
}

This has worked up to TYPO3 11.5.21.
With TYPO3 11.5.22 the Content-Type header is forced to text/html.

I suspect #99373 to cause this, but can't find the exact reason.
The correct Content-Type is set if I comment line 185 of
TYPO3\CMS\Extbase\Core\Bootstrap->handleFrontendRequest(): $response = $response->withoutHeader('Content-Type');


Files

bug99534_0.0.2_202301141542.zip (10.5 KB) bug99534_0.0.2_202301141542.zip Gregor Hermens, 2023-01-14 15:50

Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #100189: Content-Type charset is now also added for application/binary Extbase responsesResolvedBenni Mack2023-03-16

Actions
Actions #1

Updated by Chris Müller over 1 year ago

  • Status changed from New to Needs Feedback

(removed) Sorry, was BS from my side ...

Actions #2

Updated by Gregor Hermens over 1 year ago

I build an extension to demonstrate the problem.

Steps to reproduce the problem:

  1. Install EXT:bug99534 from https://github.com/ghermens/bug99534.git or the attached file.
  2. Include the TS template on an empty page.
  3. Open this page in the browser.

Actual result

In TYPO3 11.5.22, the Content-Type header is set to 'text/html; charset=UTF-8'. The browser dumps the source of the file.

Expected result

Up to TYPO3 11.5.21, the Content-Type header is set to 'application/pdf'. The browser handles the file by opening an application assigned to this Content-Type or downloading the file.

Cause

With #99373, \TYPO3\CMS\Extbase\Core\Bootstrap->handleFrontendRequest() removes the Content-Type from the response not only for application/json, but for all types. The Content-Type is written to \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->setContentType() instead.
In \TYPO3CMS\Frontend\Http\RequestHandler->handle() the Content-Type is restored to the final response in line 171:

$response = $controller->applyHttpHeadersToResponse($response);

However, if config.disableCharset = 1 is set, \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->applyHttpHeadersToResponse() sets no Content-Type at all:

// Set header for charset-encoding unless disabled
if (empty($this->config['config']['disableCharsetHeader'])) {
    $response = $response->withHeader('Content-Type', $this->contentType . '; charset=' . trim($this->metaCharset));
}

Possible Solution

config.disableCharset = 1 should only disable the charset part of the Content-Type, i.e.:

// Set header for charset-encoding unless disabled
if (empty($this->config['config']['disableCharsetHeader'])) {
    $response = $response->withHeader('Content-Type', $this->contentType . '; charset=' . trim($this->metaCharset));
} else {
    $response = $response->withHeader('Content-Type', $this->contentType);
}

Workaround

With config.disableCharset = 0, the Content-Type is set to 'application/pdf; charset=utf-8'. The additional charset parameter seems to be no problem.
In TYPO3 12, disableCharset is removed (without deprecation?) anyway: #97550

But for TYPO3 11 this imho is a breaking change, which should not happen in a LTS version.

Throwing a PropagateResponseException as indicated by Chris Müller will work, too. This is also the cleanest solution as the stripped down target page is not needed at all.

Actions #3

Updated by Chris Müller over 1 year ago

  • Status changed from Needs Feedback to New
Actions #4

Updated by Benni Mack 9 months ago

  • Sprint Focus set to On Location Sprint
Actions #5

Updated by JAKOTA Design Group GmbH 9 months ago

Hi, I believe this has been fixed with:

https://forge.typo3.org/issues/100189

Actions #6

Updated by Benni Mack about 2 months ago

  • Related to Bug #100189: Content-Type charset is now also added for application/binary Extbase responses added
Actions #7

Updated by Benni Mack about 2 months ago

  • Status changed from New to Closed

Fixed in latest v12 LTS.

Actions

Also available in: Atom PDF