Skip to content

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

@philsttr

Description

@philsttr

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.)

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions