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

MediaType isn't extensible #656

Open
mredig opened this issue Jan 15, 2025 · 4 comments · May be fixed by #657
Open

MediaType isn't extensible #656

mredig opened this issue Jan 15, 2025 · 4 comments · May be fixed by #657

Comments

@mredig
Copy link
Contributor

mredig commented Jan 15, 2025

I am currently working on an HLS server and was working to serve the stream components through HB, however when I load an m3u8 file through FileMiddleware, there's no definition for m3u8 in MediaType so the browser just attempts to load it as plain text.

Obviously, the simplest solution would be to just add m3u8 to MediaType.extensionMap, but I think that's just a band aid. Devs should be able to define additional MediaTypes that can be used by FileMiddleware.

I would propose that MediaType.extensionMap be made privately mutable and to add a static registerAdditionalType(_ type: MediaType, withExtension ext: String) to MediaType (or, if scoping is preferable for some reason I can't foresee, perhaps registering on an instance of FileMiddleware)

I'd be happy to make a PR for this if you guys are onboard.

@adam-fowler
Copy link
Member

I would propose that MediaType.extensionMap be made privately mutable and to add a static registerAdditionalType(_ type: MediaType, withExtension ext: String) to MediaType (or, if scoping is preferable for some reason I can't foresee, perhaps registering on an instance of FileMiddleware)

Making MediaType.extensionMap privately mutable will have Sendability issues. It might be better to add an extension, media type map to FileMiddleware.

@mredig
Copy link
Contributor Author

mredig commented Jan 15, 2025

What would be the downside of wrapping access to the property in a lock, to maintain Sendability safety?

@mredig
Copy link
Contributor Author

mredig commented Jan 15, 2025

It might be better to add an extension, media type map to FileMiddleware.

If we do this, I assume we'd want to leave extensionMap on MediaType and just copy it as a starting place on FileMiddleware instances?

@mredig
Copy link
Contributor Author

mredig commented Jan 15, 2025

I created a PR with the latter idea. Let me know if you have any suggestions or would prefer a different approach.

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 a pull request may close this issue.

2 participants