Cache 200 file_server Responses

I would like to cache some file_server responses. Anything under /assets/* which returns a status 200.

I can do part of this with request matchers:

example.com {
	root * /var/www/html
	@assets {
		method GET
		path /assets/*
	}
	header @assets Cache-Control "max-age=31536000"
	file_server
}

Works great. But I’m not sure how to also apply a response matcher and ensure this only happens for responses with a status of 200. Currently 404 requests also get the Cache-Control header, and I would like to prevent that.

Caddy version: v2.10.2 h1:g/gTYjGMD0dec+UgMw8SnfmJ3I9+M2TdvoRL/Ovu6U8=.

1 Like
example.com {

	@assets {
		method GET
		path /assets/*
	}

	root * /var/www/html
	file_server

	intercept {
		@200 status 200
		handle_response @200 {
			header @assets Cache-Control "max-age=31536000"
		}
	}
}
2 Likes