Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle 'common' web file MIME types #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

eddmann
Copy link

@eddmann eddmann commented Jan 16, 2025

This handles serving 'common' (js, css, html) file types within the static assets middleware. The returned MIME type for these files is text/plain and based on this we attempt to determine the correct MIME type via their file extension.

This is by no means an exhaustive list but provides support for files which would be typical for a web application.

This handles serving 'common' (js, css, html) file types within the static assets middleware.
The returned MIME type for these files is `text/plain` and based on this we attempt to determine the correct MIME type via their file extension.
This is by no means an exhaustive list but provides support for files which would be typical for a web application.
@@ -43,12 +43,20 @@ public function handle(Request $request, Closure $next)
protected function getMimeType(string $file)
{
$mimeType = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file);
$mimeType = strstr($mimeType, ';', true);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Work on this initially arose due to an issue with this line, the returned MIME type does not look to include a ; and as such returns false. This results in the MIME type always being empty and the 'Content-Type' subsequently being empty in the response.

If the need for this change is not deemed nessary, I would be happy to put together another MR which fixes this issue. We could either:

  • Remove the line, as upon testing I did not noticed any ; (i.e. including the charset) in the MIME type response
  • Appending a ; to the MIME type output so it will always be found and the correct part of the MIME type is returned.

Copy link
Member

@mnapoli mnapoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Edd, thanks for the PR!

Honestly if that works out better with these changes than without, I'm all 👍

Let's give it a few days to see if someone has some feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants