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

Allow customization of file extension to media type map for WebFlux static resources #26170

Closed
philsttr opened this issue Nov 27, 2020 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@philsttr
Copy link

philsttr commented Nov 27, 2020

I'd like the ability to easily customize the file extension -> media type map used for serving static resources in a WebFlux application. Specifically, I'd like a simple method to be able to register a new mapping, or change an existing mapping.

Currently, ResourceWebHandler and ResourceHttpMessageWriter both call MediaTypeFactory.getMediaType(resource) to determine the media type of a resource. MediaTypeFactory loads its mappings from the /org/springframework/http/mime.types file on the classpath. As far as I can tell, there is no easy way to customize these mappings in a WebFlux application. (It looks like you could technically extend ResourceHttpMessageWriter to customizer the resolution of the media type, but most of what is needed is private, so it would basically require re-implementing most of the logic in ResourceHttpMessageWriter. This is pretty heavyweight for just adding an additional mapping.)

For comparison, in a servlet-based application, the mappings can be easily customized via ConfigurableServletWebServerFactory.setMimeMappings(MimeMappings mimeMappings).

(And FWIW, I need a mapping for xsd, and would also be happy if that was added to the defaults.)

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 27, 2020
@rstoyanchev rstoyanchev self-assigned this Nov 30, 2020
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 30, 2020
@rstoyanchev rstoyanchev added this to the 5.3.2 milestone Nov 30, 2020
@rstoyanchev
Copy link
Contributor

We could add setMediaTypes(Map<String, MediaType>) to ResouceWebHandler and also expose it via ResourceHandlerRegistry for configuration in a WebFluxConfigurer. On the Spring MVC side the same property exists in ResourceHttpRequestHandler so we can make the two consistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants