http.mime

mime sets the Content-Type in a response based on the file extension in the request.

Normally, Content-Type is detected automatically for static files by sniffing the content, but this is not always possible. If you encounter responses with the wrong Content-Type or are serving content other than static files, you can use this middleware to set the right Content-Type.

Syntax

mime *ext type*

  • ext is the file extension to match, including the dot prefix.
  • type is the Content-Type

If you have a lot of MIME types to set, open a block:

mime { *ext type* }

Each line defines a MIME extension-type pair. You can have as many lines as you need in a mime block.

Examples

Customize the Content-Type of Flash files:

mime .swf application/x-shockwave-flash

For multiple files:

mime { .swf application/x-shockwave-flash .pdf application/pdf }

Need help with this feature?

Join us in the Caddy forum, where the open source community gathers to share their knowledge.

Does your company use Caddy?

Purchase a commercial license to use Caddy with your business and for basic email support, along with other benefits!