epicagency / caddy-expires

Provides a directive to add expires headers to certain paths
MIT License
4 stars 3 forks source link

Support mime type matching instead of regexes #5

Closed bendem closed 5 years ago

bendem commented 6 years ago

Some web applications don't always have an extension, I'd like to set expiration header based on the mime type of the query instead of the path.

What would be really awesome is to allow checking any available placeholder (kind of like the rewrite the http.rewrite plugin), but I'm guessing that's much more complex.

hlidotbe commented 5 years ago

Hi, took long enough but I finally took some time to implement it.

bendem commented 5 years ago

Is this already available if I update caddy or do I need to wait for a new release?

hlidotbe commented 5 years ago

It's released on caddyserver.com. I forgot to do the release on github but caddy should use the latest version.

bendem commented 5 years ago

Alright, I tried it but I can't tell how to configure it then. I tried these and none matches any css file.

match_header content-type text/(css|js)(;.*)? 30d
match_header content-type text\/css 30d
match_header content-type .*text\/css.* 30d
match_header content-type .*text/css.* 30d

this does work though

match_header content-type .* 30d
bendem commented 5 years ago

The raw content type I'm seeing in my browser is content-type: text/css; charset=utf-8

hlidotbe commented 5 years ago

ok so the .* matching shouldn't but as it is that "normal" since it also matches an empty string.

Could you test with Content-Type ? Maybe your browser normalize to lower case but usually it's capitalized.

The / should not need escaping and just text/css should work. I'll do more tests later but I'm wondering if the mime is set early enough. Are your css files static or served through an application server ?

bendem commented 5 years ago

According to the doc, headers are case insensitive, I tried, as expected, it didn't change anything.

I tested for static files, have not tried it through a proxied connection just yet, if it helps, I can test that later.

hlidotbe commented 5 years ago

Finally had a look into that issue. Unfortunately I don't have good news. While the logic is ok, technically I can't handle headers on static content because Caddy defer to net/http ServeContent then terminate. Nothing happens after the file is served.

match_header will work on anything not static but the only header available for static files is "Server".

I'll have a look at the v2 to see if there's a way to overcome this.