Skip to content

JSON Mime Type is missing #4161

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

Closed
ghostd opened this issue Oct 13, 2015 · 6 comments
Closed

JSON Mime Type is missing #4161

ghostd opened this issue Oct 13, 2015 · 6 comments
Assignees
Milestone

Comments

@ghostd
Copy link
Contributor

ghostd commented Oct 13, 2015

Hi,

MimeMappings does not contain the standard JSON declaration. When my application serves my file.json, no HTTP Content-Type headers are sent. Firefox reads the file but generates a warning "not well formed".

Here is my current workaround:

@Component
public class ServletCustomizer implements EmbeddedServletContainerCustomizer {

    @Override
    public void customize(ConfigurableEmbeddedServletContainer container) {
        MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
        mappings.add("json", "application/json");
        container.setMimeMappings(mappings);
    }
}
@htynkn
Copy link
Contributor

htynkn commented Oct 17, 2015

I think the reason why spring-boot don't have json mime type is we are following the same mine type mappings as tomcat

@ghostd
Copy link
Contributor Author

ghostd commented Oct 17, 2015

Ok, this is an acceptable reason IMO.
But that means Tomcat java mapping does not match its XML default configuration:
https://github.com/apache/tomcat/blob/trunk/conf/web.xml#L2071

You can close this issue if the reference code is the Tomcat java version.

@wilkinsona
Copy link
Member

It's interesting that Tomcat has different defaults in Java code and in web.xml. I'd like to understand that difference and figure out which it makes most sense for us to align with.

@wilkinsona
Copy link
Member

From a conversation with @markt-asf:

conf/web.xml is used when running Tomcat ‘normally’ without o.a.c.startup.Tomcat. DEFAULT_MIME_MAPPINGS is used when using Tomcat.addWebapp(…). I believe neither are used if you use Tomcat.addContext(…)

On the reason for the difference between the two lists of mappings:

Only that we haven't kept DEFAULT_MIME_MAPPINGS up to date with changes in conf/web.xml

Some advice on a definitive source for mime mappings:

We update conf/web.xml from httpd periodically so you might want to take httpd's list as the definitive one. Don't know where they pull updates from.

@wilkinsona
Copy link
Member

The different embedded containers have different mime mapping configurations. Both Jetty and Undertow have default mime mappings that Boot's mime mappings are then added to, whereas Tomcat just uses Boot's mime mappings. One consequence of this is that both Jetty and Undertow have a mapping for JSON while Tomcat does not.

@philwebb philwebb added this to the 1.2.8 milestone Oct 19, 2015
@philwebb
Copy link
Member

Seems sensible to add it (unless you object @wilkinsona)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants