1. Output of caddy version
:
v2.6.2
2. How I run Caddy:
a. System environment:
b. Command:
caddy run
d. My complete Caddy config:
{
debug
}
(hashcache) {
map {path} {uncached} {uncachedbool} {
~(?i)(/static|/themes)(/.*)\.([a-z0-9]{8,40})\.([a-zA-Z0-9]+)$ "${1}${2}.${4}" "yes"
default "no"
}
@uncached_map expression `{uncachedbool} == "yes"`
rewrite @uncached_map {uncached}
}
(expiresTest) {
@matchExpiresTenDays {
# use file directive to not set header on non existing file.
file
path *.png
}
header @matchExpiresTenDays Cache-Control max-age=864000
}
:8000 {
root * .
import hashcache
import expiresTest
file_server
}
3. The problem I’m having:
I want to set a header on a static resource that gets rewritten.
4. Error messages and/or full log output:
2022/12/14 14:40:36.971 DEBUG http.handlers.rewrite rewrote request {"request": {"remote_ip": "127.0.0.1", "remote_port": "65362", "proto": "HTTP/1.1", "method": "HEAD", "host": "localhost:8000", "uri": "/static/test.32523452352345.png", "headers": {"User-Agent": ["curl/7.84.0"], "Accept": ["*/*"]}}, "method": "HEAD", "uri": "/static/test.png"}
2022/12/14 14:40:36.971 DEBUG http.handlers.file_server sanitized path join {"site_root": ".", "request_path": "/static/test.png", "result": "static/test.png"}
2022/12/14 14:40:36.971 DEBUG http.handlers.file_server opening file {"filename": "static/test.png"}
5. What I already tried:
Request the existing file as is - the Cache-Control with intended max-age is set:
# curl -I http://localhost:8000/static/test.png
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: max-age=864000
Content-Length: 22417
Content-Type: image/png
Etag: "rmvx8phap"
Last-Modified: Wed, 14 Dec 2022 14:22:01 GMT
Server: Caddy
Date: Wed, 14 Dec 2022 14:42:10 GMT
Request the existing file in a way it is rewritten - Cache-Control is missing:
# curl -I http://localhost:8000/static/test.32523452352345.png
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 22417
Content-Type: image/png
Etag: "rmvx8phap"
Last-Modified: Wed, 14 Dec 2022 14:22:01 GMT
Server: Caddy
Date: Wed, 14 Dec 2022 14:42:19 GMT