Problem/Motivation

Drupal's mime type guesser is not registered with the symfony service. Therefore, if the Symfony guesser is accessed directly (e.g., in a Response object) the Drupal service is not used. In Drupal 8 this was registered but that code was since removed in error, so we are adding it back and completing the registration using current methods.

Steps to reproduce

See failing test in MR. Mime types are not properly guessed from file extensions, e.g. when sending binary files.

Proposed resolution

Register the MIME guesser in the same fashion it was previously.

Remaining tasks

Review

User interface changes

N/A.

API changes

None.

Data model changes

None.

Release notes snippet

N/A.

Issue fork drupal-3172550

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new4.53 KB

Status: Needs review » Needs work

The last submitted patch, 2: 3172550-2.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new499 bytes
new4.58 KB

Fix the test - the test failed because of statics.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

bradjones1’s picture

Retesting against 9.3.x. The "new" Symfony 5 mime type guesser was added in #3055193: [Symfony 5] The "Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser" class is deprecated since Symfony 4.3, use "Symfony\Component\Mime\MimeTypes" instead.. This causes difficult-to-diagnose issues such as #3216534: BinaryFileResponse can fail to provide the appropriate content type which I just marked as a duplicate of this issue.

bradjones1’s picture

Priority: Normal » Major

Being bold and marking this major as it results in empty responses for binary file responses.

bradjones1’s picture

Status: Needs review » Reviewed & tested by the community

I came here basically with the same patch, and this is rather straightforward. Nice that it still passes tests against 9.3.x.

Only nit would be, does this need some sort of @todo to remove when Drupal 10 drops Symfony 4?

Marking RTBC to get some maintainer eyes.

alexpott’s picture

@bradjones1 I don't think we need a todo - when we drop Sf4 support or try this with Symfony 5 we'll have to touch this code.

longwave’s picture

Is it worth also taking the test from the closed duplicate issue as insurance against breaking this again? Testing that binary files have the correct content type seems a reasonable thing to do, and implies we don't have any other end to end coverage that uses this feature.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

@longwave that seems like a great idea.

alexpott credited DuaelFr.

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new4.21 KB
new8.79 KB

Here's the test from the duplicate issue. Creditting @DuaelFr as they wrote it.

The last submitted patch, 14: 3172550-2-13.test-only.patch, failed testing. View results

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

wim leers’s picture

AFAICT this is still a bug today … I just wrote failing test coverage for the CDN module at #3300982-4: Drupal core regression: CDN's "far future" responses have wrong Content-Type response header.

wim leers’s picture

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new146 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

catch’s picture

A lot of the singleton logic has gone from Drupal 10. There's new test coverage here though, so maybe we want to commit (some of?) that anyway? Sent the test-only patch for a re-test against 10.1.x

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

driskell’s picture

I just discovered this after some hard waiting for reproduction scenarios.

Downloaded a specific CSS file and it seems that the fallback to file_info picks it up as assembler source text - delivering text/x-asm! Of course, this only happens for an uncached hit to an aggregation - subsequent will pick it up. So it just is annoying. I'll raise as a separate issue on AssetControllerBase but this is related I believe.

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

catch’s picture

longwave’s picture

Issue tags: +Needs reroll

In #3197482: Update Drupal 10 to depend on Symfony 5.4 (as a stepping stone to Symfony 6, for deprecation checking support) we removed MimeTypeGuesser::registerWithSymfonyGuesser() entirely, was this a mistake?

If it is still needed this needs rerolling considering the registration method was removed entirely. I guess the additional test coverage should tell us if this is necessary.

bradjones1’s picture

Status: Needs work » Closed (outdated)

I believe this is outdated. Was trying to do some archaeology on my side to determine if this would still be necessary but I think the answer is no. Comports with my note in #9 that this would no longer be necessary in D10.

duaelfr’s picture

Status: Closed (outdated) » Needs review
Issue tags: -Needs reroll
StatusFileSize
new4.46 KB

Given #22 and #26 I rerolled the tests to see what the testbot has to say about this old issue.

DuaelFr changed the visibility of the branch 3172550-register-drupals-mime to hidden.

duaelfr’s picture

Status: Needs review » Needs work

Given the tests results
https://git.drupalcode.org/issue/drupal-3172550/-/jobs/1533523#L2239

It seems that this issue is not that outdated!

bradjones1’s picture

Ah, thank you! I couldn't for the life of me remember _why_ I was here in the first place but this helped jog my memory.

I think per #26 then, we can consider that #3197482: Update Drupal 10 to depend on Symfony 5.4 (as a stepping stone to Symfony 6, for deprecation checking support) resulted in a regression and this should be high priority for 11.0...

bradjones1’s picture

Status: Needs work » Needs review
Issue tags: +Regression

OK, this should be good for review, now. I do believe this is a pretty significant regression on binary file handling.

Needed to update a config validation test that was depending on the default Symfony mimetype guesser's fileinfo implementation to pass.

bradjones1’s picture

Title: Register Drupal's mime guesser with the non legacy Symfomy singleton » Register Drupal's mime type guesser the Symfony MimeTypes service
smustgrave’s picture

Issue summary: View changes
Status: Needs review » Needs work

Can the issue summary be filled in. I put a TBD for sections that may apply but if they didn't can change to N/A

bradjones1’s picture

Issue summary: View changes
Status: Needs work » Needs review
bradjones1’s picture

Issue summary: View changes
bradjones1’s picture

smustgrave’s picture

Status: Needs review » Needs work

Thanks for updating! Looking again

In Drupal 9 we should be registering with both and then in Drupal 10 we should remove the legacy registration.

Believe this no longer applies?

bradjones1’s picture

Issue summary: View changes
Status: Needs work » Needs review

IS updated.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new3.97 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

bradjones1’s picture

Status: Needs work » Needs review

bradjones1 changed the visibility of the branch 3172550-register-drupals-mime to active.

bradjones1 changed the visibility of the branch 3172550-register-drupals-mime to hidden.

bradjones1’s picture

Updated.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Meant to post in my previous comment but test coverage exists and can be seen here https://git.drupalcode.org/issue/drupal-3172550/-/jobs/1631442

Believe all feedback has been addressed and change does appear to make sense with the register.

catch’s picture

There's a @todo linking to this issue in AssetControllerBase - I've removed the one line of code plus the comment, and confirmed the explicit test coverage we added for it still pass for me locally. Will go ahead and commit once gitlab comes back green. Nice to get rid of that.

  • catch committed 6b3c7aa5 on 10.3.x
    Issue #3172550 by bradjones1, DuaelFr, alexpott, smustgrave, longwave:...

  • catch committed e244a823 on 11.0.x
    Issue #3172550 by bradjones1, DuaelFr, alexpott, smustgrave, longwave:...

  • catch committed 6fbf4f4e on 11.x
    Issue #3172550 by bradjones1, DuaelFr, alexpott, smustgrave, longwave:...

  • catch committed 58fd9895 on 10.4.x
    Issue #3172550 by bradjones1, DuaelFr, alexpott, smustgrave, longwave:...
catch’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x and cherry-picked to 11.0.x, 10.4.x, 10.3.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.