pyed / ipfilter

ipfilter is a middleware for Caddy that blocks or allows requests based on the client's IP
https://caddyserver.com/docs/ipfilter
Apache License 2.0
83 stars 19 forks source link

Content Type not set when gzip middleware is enabled #28

Closed jonesnc closed 6 years ago

jonesnc commented 6 years ago

I'll quote this post made by Matthew Fay on the Caddy support forum here, since I'm not really familiar with this codebase:

The gzip directive operates early on in the middleware chain, but it simply swaps out the default ResponseWriter for a gzipWriter so anything written by later middleware such as ipfilter is compressed.

If you take a look at the ipfilter code handling blocked pages, it doesn’t look like a Content-Type header is set anywhere when the nominated block page is written. For an example of code that sets the Content-Type while returning a nominated HTML document, see this code in the built-in errors plugin 1.

When a browser receives a compressed file without a content type, it can’t make the assumption that it’s HTML intended to be rendered, so it downloads it instead. I’d wager that’s the cause of your problem.

pyed commented 6 years ago

Fixed, thank you for reporting