Howdy @andre, welcome to the Caddy community.
Caddy’s static fileserver doesn’t actually write the Content-Type header, it instead leverages the Go standard library to handle this while serving the file.
Here’s the behaviour of http.ServeContent:
If the response’s Content-Type header is not set, ServeContent first tries to deduce the type from name’s file extension and, if that fails, falls back to reading the first block of the content and passing it to DetectContentType.
—http package - net/http - Go Packages
This doesn’t look good for your scenario, though. There’s two things I can think of to try:
- Rewrite to a
.html file in case mime picks up the rewritten extension
Because rewrite executes before mime does, you might be able to rename index.html to home.html or similar and put in a rewrite from the index to the HTML file:
rewrite {
if {path} is /
to /home.html
}
Renaming the file on disk away from index.html is necessary because the static fileserver will otherwise canonically redirect it back to /.
This may not work - I haven’t tested it - but I suspect mime will pick up the rewritten file and to your visitors it will simply work. If it doesn’t, the next option is…
- Rewrite internally to a folder you know nobody’s going to use
Move index.html to foo/index.html, then rewrite:
rewrite {
if {path} is /
to /foo/
}
Then add header /foo/ Content-Type "text/html; charset=ISO-8859-1" to override the Content-Type header for this entire area.
Unfortunately, both options look a bit ugly.