question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to add custom mime type - ("java.lang.IllegalStateException: contentType must not be null")

See original GitHub issue

Actual 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:closed
  • Created 2 years ago
  • Comments:14 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
shafique-md18commented, Aug 29, 2021

@tipsy I didn’t know that! Actually, this is my first time contributing to opensource projects.

I’ll submit a PR to fix this.

1reaction
tipsycommented, Aug 28, 2021

@shafique-md18 I think you can go ahead, it’s rare for people to start working on a pull request without saying they will 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sending vendor content type with jMeter throws ...
To do this, I put vendor content-type application/vnd.anything.process+json;ver=1 as a MIME type for this file. Unfortunately, jMeter throws ...
Read more >
RequestMapping Content-Type error when a @RequestBody ...
In PostMan, when I don't have the Content-Type set, use a POST, and don't add data to the request, it's successful in 1.2.1....
Read more >
File download fails due to unsupported content types - Forums
here it first tries to get the Mime type from portlet context which is null in my case. Then it tries to call...
Read more >
Web on Reactive Stack - Spring
As a general rule, a WebFlux API accepts a plain Publisher as input, adapts it to a Reactor type internally, uses that, and...
Read more >
Jersey 2.37 User Guide - GitHub Pages
Custom Java type for consuming request parameters; 3.10. ... Accept: */* > * Mark bundle as not supporting multiuse < HTTP/1.1 200 OK...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found