AssetControllerBase returns BinaryFileResponse with missing Content-Type, resulting in spurious Content-Type headers

Created on 19 July 2023, 11 months ago
Updated 24 July 2023, 11 months ago

Problem/Motivation

When an asset is generated multiple times and a second request to AssetController sees that the file already exists and delivers it - the BinaryFileResponse does not specify a Content-Type.

Since D10 it seems there is no registered guesser like in D9 so it uses file_info or similar. This is notoriously inaccurate.

For example, the below bundle file is detected as assembler source text (text/x-asm) and multiple other of my bundles are detected as text/plain. This prevents the browser from loading them.

css_po4KdqlRZWF8CfE0QBHXRKXwhj22MhbNT8WiGLDtx9w.css: assembler source text, ASCII text, with very long lines (24366)

Mitigation is that this only happens in a race during initial generation - subsequent requests are directly handled by static file serving of the web server and do not go via PHP and so use a more reliable static content type MIME table in most cases. But this is fairly frustrating as it can happen during deployments where JS changes occur, and can raise false alarms of a deployment issue.

Steps to reproduce

Turn off static file serving in Apache or Nginx and push asset requests always to PHP.
This will simulate requests going to PHP for a JS/CSS aggregate that already exists because another parallel request finished processing it that same moment.

Proposed resolution

Add content-type header to BinaryFileResponse

Remaining tasks

-

User interface changes

-

API changes

-

Data model changes

-

Release notes snippet

-

πŸ› Bug report
Status

Closed: duplicate

Version

10.1 ✨

Component
SystemΒ  β†’

Last updated 1 day ago

No maintainer
Created by

πŸ‡¬πŸ‡§United Kingdom Driskell

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024