Allow customization of file extension to media type map for WebFlux static resources #26170
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
type: enhancement
A general enhancement
Milestone
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
andResourceHttpMessageWriter
both callMediaTypeFactory.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 extendResourceHttpMessageWriter
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 inResourceHttpMessageWriter
. 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.)The text was updated successfully, but these errors were encountered: