How to override MIME type?

I’ve looked at templates (Caddyfile directive) — Caddy Documentation, but don’t understand how to override a sent/configured mime type.

In particular, I want to have FLAC files sent as audio/flac not audio/x-flac as the latter is actually non-standard, according to Mozilla (and it breaks FLAC embeds in The Lounge to send the latter).

Note: I use Caddyfile, not JSON.

In nginx you just use something like server-configs-nginx/mime.types at main · h5bp/server-configs-nginx · GitHub to accomplish the goal.

How would I accomplish this with Caddy/Caddyfile?

1 Like

I was reviewing some code to see if there was anything I could submit a PR for, perhaps, but I don’t really know what I’m looking at. :smiley: Don’t know that a PR would be accepted to make the FLAC mime type match MDN, but… ¯\_(ツ)_/¯

These appear to be all the files that reference mime in any way.

1 Like

See this issue, where someone asked the same question:

1 Like

Dang, can’t believe I missed that one searching GitHub. Bleh.

That basically sets the Content-Type header, right?

So wouldn’t you just need:

@html path *.html
header @html Content-Type application/x-httpd-php

Or something like that?

This solution from Matt does seem to work nice for one-offs. Would seem a bit extreme to use this method to define many things.

Go pulls the mime types from your system’s mailcap file locations, see if you can add any mappings in there. Quick google search brought me to Ubuntu Manpage: update-mime - create or update MIME information, which may be relevant depending on your OS.

I don’t think this is something we’d need in Caddy’s core, you could possibly write a plugin to add overrides using the mime package - mime - Go Packages stdlib package. You can find the docs for Caddy plugins here: Extending Caddy — Caddy Documentation

I took a look at mime package - mime - Go Packages as well and see that you can indeed map a mime.types file a la nginx, but the formatting appears to be different and picky, so I’ll have to adjust my current file to make golang’s mime library happy, I guess. At least I’ll only have to do it once… :sweat_smile:

2 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.