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

http/file-server, media_types: new addition application/mp4 to mime db overrides video/mp4 and breaks some net players #5433

Closed
NaitLee opened this issue Jul 13, 2024 · 7 comments · Fixed by #5475
Labels
bug Something isn't working http

Comments

@NaitLee
Copy link

NaitLee commented Jul 13, 2024

Describe the bug
New addition application/mp4 to media_types/vendor/db.ts (#2286) overrides video/mp4 for the contentType function. As file-server specifies content-type by that function and the db, it breaks some network-capable video players which expecting the mimetype to be video/*, because the received mimetype application/mp4 is unexpected, they won't play the video anymore

Steps to Reproduce

  1. Start newest file-server inside a folder with some mp4
$ deno run --allow-read --allow-net --allow-sys jsr:@std/[email protected]/file-server
Listening on:
- Local: http://localhost:8000
- Network: http://192.168.2.103:8000
  1. Issue a HEAD request to any video:
$ curl --head http://localhost:8000/1.mp4
HTTP/1.1 200 OK
...
content-type: application/mp4
...
  1. The content-type is the new addition application/mp4, as it wins video/mp4. This breaks some network players as stated, as they don't identify application/mp4; they only know about video/mp4

Expected behavior

  1. Start an older version of file-server, without the mimetype update
$ deno run --allow-read --allow-net --allow-sys jsr:@std/[email protected]/file-server
Listening on:
- Local: http://localhost:4507
- Network: http://192.168.2.103:4507
  1. Issue a HEAD request to any video:
$ curl --head http://localhost:4507/1.mp4
HTTP/1.1 200 OK
...
content-type: video/mp4
...
  1. as the mimetype video/mp4 is by far the most preferred, it always worked for most (if not all) network players

Environment

  • OS: any
  • deno version: 1.45.2
  • std version:
    • @std/media_types after the commit 6d58a57
    • @std/http 0.224.1 and above

P.S.

I think we need a smarter contentType function or mimetypes db that has preference over the "best" mimetype for certain file extensions. I see a similar problem had happened on application/javascript over text/javascript (#5186), probably there are far more media types are affected.

Likely that most players affected by this are proprietary, so fixing all the players is not feasible.

@NaitLee NaitLee added bug Something isn't working needs triage labels Jul 13, 2024
@iuioiua
Copy link
Contributor

iuioiua commented Jul 15, 2024

Thank you for testing @std/[email protected] out. This bug should be addressed before stabilization.

Currently, the value of the content-type header is determined from the extension in the URL. Instead, we should gather all possible content-types for a given extension (i.e. something like a version of contentType that returns an array of possible content-types instead of just one), then use accepts to determine the most appropriate content-type, based on the client's request.

Any thoughts, @kitsonk?

@iuioiua iuioiua added http and removed needs triage labels Jul 15, 2024
@kt3k
Copy link
Member

kt3k commented Jul 17, 2024

Looks like this is affected by this change in the upstream jshttp/mime-db@48e4115

@kt3k
Copy link
Member

kt3k commented Jul 17, 2024

@NaitLee Do you know if those players send accept headers when requesting mp4 files?

@kt3k
Copy link
Member

kt3k commented Jul 17, 2024

I think we should just return video/mp4 for contentType(".mp4") (and typeByExtension(".mp4")) by defining our preference in media_types/_db.ts.

@kt3k
Copy link
Member

kt3k commented Jul 17, 2024

@NaitLee
Copy link
Author

NaitLee commented Jul 17, 2024

@NaitLee Do you know if those players send accept headers when requesting mp4 files?

in my test, none of android vlc, mpv, and other numerous players i've tested send accepts header.

i'm wondering if application/x is always "the least prefered type" if other types like video/x or text/x are around. if that's the case just prefer those over application/x one.

in my mind the preference can be video > audio > image > text > application, it's at least correct for mp4, ogg, svg, and javascript, probably ok for .ts too.

@iuioiua iuioiua added the PR welcome A pull request for this issue would be welcome label Jul 18, 2024
@kt3k kt3k removed the PR welcome A pull request for this issue would be welcome label Jul 18, 2024
@kt3k
Copy link
Member

kt3k commented Jul 18, 2024

Looks like there's a line that implements the preference of application/* types over other types

(from === to && current.startsWith("application/")))

The line exists from the beginning of the package: https://github.com/denoland/std/pull/2286/files#diff-92e0917a6de42a1319f4f29e026ba39b73bf1dc70dececdcbced2d732b018d99R60

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working http
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants