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

Does match_path support wildcard or regex ? #17

Closed
chinajuanbob opened this issue Jun 23, 2020 · 9 comments · Fixed by #20 or #21
Closed

Does match_path support wildcard or regex ? #17

chinajuanbob opened this issue Jun 23, 2020 · 9 comments · Fixed by #20 or #21

Comments

@chinajuanbob
Copy link

When working with file_server browse of the caddy, I only want files (or the ones of certain types) to be cached, but not the directories.

Does match_path support it?

Thanks!

@sillygod
Copy link
Owner

Hi @chinajuanbob,

Maybe, you can use match_heaer to achieve your goal.

ex.

:9991  {

    reverse_proxy {
        to localhost:9995
    }

    http_cache {

        cache_type in_memory
        match_path /
        match_header Content-Type image/jpg image/png "text/plain; charset=utf-8"

    }

However, I found the match_header doesn't work correctly. I will do a fix for it soon.

@sillygod
Copy link
Owner

@chinajuanbob ,

I've created the latest release 0.3.4. You can use match_header to filter the content types you want to cache.

@chinajuanbob
Copy link
Author

hit this:

:2020 {
    reverse_proxy {
        to localhost:2021
    }
    http_cache {
        cache_type in_memory 
        match_path /
        match_header Content-Type image/jpg image/png "text/plain; charset=utf-8"
    }
}
$ curl -I http://localhost:2021/uploadtest    
HTTP/1.1 404 Not Found
Server: Caddy
Date: Tue, 23 Jun 2020 10:29:50 GMT

$ curl -I http://localhost:2020/uploadtest    
HTTP/1.1 200 OK <------------------------ should be 404 here
Date: Tue, 23 Jun 2020 10:29:55 GMT
Server: Caddy
X-Cache-Status: skip

@sillygod
Copy link
Owner

Oops, I know the root cause! I will make a fix for this.

@sillygod
Copy link
Owner

Hi @chinajuanbob ,

Thanks for testing it. I've pushed a fix for the problem. the latest release is v0.3.6

@chinajuanbob
Copy link
Author

The 404 issue is gone, however, hit this:

:2020 {
    reverse_proxy {
        to localhost:2021
    }
    http_cache {
        cache_type in_memory 
        match_path /
        match_header Content-Type image/jpeg
    }
}
$ curl -I http://localhost:2021/uploadtest.jpg
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 5
Content-Type: image/jpeg
Etag: "qcf73l5"
Last-Modified: Wed, 24 Jun 2020 07:50:09 GMT
Server: Caddy
Date: Wed, 24 Jun 2020 07:50:16 GMT

$ curl -I http://localhost:2020/uploadtest.jpg
HTTP/1.1 200 OK
Accept-Ranges: bytes
Accept-Ranges: bytes. <-------- duplicated
Content-Length: 5
Content-Length: 5
Content-Type: image/jpeg
Content-Type: image/jpeg
Date: Wed, 24 Jun 2020 07:50:09 GMT
Date: Wed, 24 Jun 2020 07:50:21 GMT
Etag: "qcf73l5"
Etag: "qcf73l5"
Last-Modified: Wed, 24 Jun 2020 07:50:09 GMT
Last-Modified: Wed, 24 Jun 2020 07:50:09 GMT
Server: Caddy
X-Cache-Status: miss <--------- keep 'miss' after request for multiple times 

@sillygod
Copy link
Owner

sillygod commented Jun 24, 2020

@chinajuanbob ,

Do you know what curl -I does internally? If I just use curl [URL], it will work well.
OK, this will issue a HTTP HEAD method.

There is some unexpected behavior when receiving the request with the head method. I push a fix about it. the latest release is v0.3.7. Thanks for finding this extra bugs.

This was linked to pull requests Jun 24, 2020
@sillygod
Copy link
Owner

sillygod commented Jul 3, 2020

Hi @chinajuanbob ,

Did you encounter any problem with the latest release? If no, I will close this issue a few days later.

@chinajuanbob
Copy link
Author

Thanks @sillygod for the quick fix! I just try the case again and the problem is gone. We could close it for now.

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

Successfully merging a pull request may close this issue.

2 participants