Page tree
Skip to end of metadata
Go to start of metadata

This page explains how MIME types (media types, content types) are mapped to file extensions in Magnolia.

Configuration

MIME types are configured in config:/server/MIMEMapping. You can edit them with the Configuration app.

Example: The MIME type text/html is mapped to extension html. The type application/x-javascript is mapped to extension js.

Node namevalue

 server


 MIMEMapping


 html


 mime-type

text/html

  foobar


  mime-type

application/x-javascript

 ext

js

The example above shows just two types. Magnolia configures many more MIME types by default.

Properties:

<node‑name>

required

Parent node name such as html, used as the extension when no ext property is defined. If you want to use an arbitrary name, configure the ext property.

mime‑type

required

MIME type for the given file extension. See Official list of media types.

ext

optional

File extension. If not set, <node-name> is used.

ContentTypeFilter

ContentTypeFilter is a filter in the Magnolia filter chain

(warning) Since Magnolia 5.4.5+, ContentTypeFilter is no more setting the response content type, instead it's the responsibility of renderers/servlets to set correct content type (for instance FreemarkerRenderer sets the content type). However, ContentTypeFilter sets some parameters onto AggregationState and takes care of restricting responses to configured MIME types and matching requests to content types..

Restricting responses to configured MIME types

(warning) Magnolia 5.4.2+

By default, Magnolia tries to respond to every request - even if the MIME type is not configured. To restrict responses to configured MIME types only, add a registeredExtensionsOnly property to the contentType filter configuration: 

Node namevalue

 server


 filters


 contentType


 class

info.magnolia.cms.filters.ContentTypeFilter

 enabled

true

  registeredExtensionsOnly

true

When registeredExtensionsOnly is true Magnolia will respond with response code 400 to requests with extensions that are not registered in MIMEMapping. 

If the request has no extension, Magnolia assumes it is html.

Matching requests to content types

(warning) Magnolia 5.4.3+

You can restrict responses to match content types with the validateContentType property. 

Example: If you request https://demopublic.magnolia-cms.com/travel.c, the HTML source is returned because of the text/plain MIME mapping in /server/MIMEMapping/c

To force content type matching, add the validateContentType property in server/filters/contentType and set the value to true.

Node namevalue

 server


 filters


 contentType


 class

info.magnolia.cms.filters.ContentTypeFilter

 enabled

true

  registeredExtensionsOnly

true

  validateContentType

true

When the validateContentType property is set to true, Magnolia will respond with  response code 400 if the requested extension does not match the content type. This property essentially disables all unknown extensions.