Unable to add custom mime type - ("java.lang.IllegalStateException: contentType must not be null")
See original GitHub issueActual behavior (the bug) When serving up a static page, using compression, with an extension that does not have a default mimeType (i.e. md) associated with it an exception is thrown (java.lang.IllegalStateException: contentType must not be null). Associating the extension with a mime-type does not help.
config.configureServletContextHandler( (context) -> {
context.getMimeTypes().addMimeMapping("md", "text/plain");
});
Expected behavior When the mimeMapping is added the .md file should download correctly without an exception.
To Reproduce Create an instance with compression enabled and add a custom mapping for *.md files
config.compressionStrategy(new Brotli(4), new Gzip(6));
config.addStaticFiles(staticFileLocation, Location.EXTERNAL);
config.configureServletContextHandler( (context) -> {
context.getMimeTypes().addMimeMapping("md", "text/plain");
});
Place a .md (markdown) file into the static file location and then attempt to retrieve that file in a browser from the server.
Additional context
This medhod:
context.getMimeTypes().addMimeMapping("md", "text/plain");
adds the specified mapping to a map __mimeMap.
However, the handle function in PrecompressingResourceHandler.kt uses this:
val contentType = MimeTypes.getDefaultMimeByExtension(target)
That method, according to the javadoc, will “Lookup only the static default mime map”. That means it looks for a mapping in the default mime map (__dftMimeMap), but does not look in __mimeMap where the custom mapping has been added. Instead of “getDefaultMimeByExtension” the handle function should call “getMimeByExtension”, which will look in both the default and custom mappings for a match.
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (13 by maintainers)
Top GitHub Comments
@tipsy I didn’t know that! Actually, this is my first time contributing to opensource projects.
I’ll submit a PR to fix this.
@shafique-md18 I think you can go ahead, it’s rare for people to start working on a pull request without saying they will 😃