Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mime type matching instead of regexes #5

Closed
bendem opened this issue Oct 3, 2018 · 8 comments
Closed

Support mime type matching instead of regexes #5

bendem opened this issue Oct 3, 2018 · 8 comments

Comments

@bendem
Copy link

bendem commented Oct 3, 2018

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 added a commit that referenced this issue Mar 17, 2019
Rewrote the matching rules to support header matching in addition to
path matching.
@hlidotbe
Copy link
Member

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

@bendem
Copy link
Author

bendem commented Apr 2, 2019

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

@hlidotbe
Copy link
Member

hlidotbe commented Apr 2, 2019

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

@bendem
Copy link
Author

bendem commented Apr 2, 2019

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
Copy link
Author

bendem commented Apr 2, 2019

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

@hlidotbe hlidotbe reopened this Apr 2, 2019
@hlidotbe
Copy link
Member

hlidotbe commented Apr 2, 2019

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
Copy link
Author

bendem commented Apr 2, 2019

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
Copy link
Member

hlidotbe commented Oct 8, 2019

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.

@hlidotbe hlidotbe closed this as completed Oct 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants