caddy-cache
caddy-cache copied to clipboard
Cached images only downloading last byte
I'm trying out the cache plugin on my personal site and am seeing some images being downloaded with a Content-Length of 1, for example: https://matt.life/resources/images/lake.jpg
This is downloaded with a content of Ü and a content-range header of just the last byte. You can see the rest of them like this on https://matt.life.
I've been noticing some image errors as well. I hadn't looked into it yet because it was just development, hadn't moved anything to production yet.
@mholt what was the original request? I have disabled (bypass) requests with accept-range (https://github.com/nicolasazrak/caddy-cache/blob/master/handler.go#L86) because those are not currently supported. The image from the link seems to be responding with a 206 status code and content-range.
I probably should disable cache if any of those are present in the response until partial responses are fully supported.
Edit: looking at the code I was a little confused: accept-range is a response header, and I was filtering request headers. It was never going to work.
Yeah, that response header is also why I'm confused. I haven't seen it before I enabled the cache plugin (simply added cache to the Caddyfile), so I figured it is related to the plugin. You can see the original requests on the site https://matt.life by using the inspector.
I could reproduce the issue using curl sending a request with range header to a test image. In that case a accept-range appears in the response as expected. Normally range is not sent, but it seems that somebody made a request with that to your page and it got cached. Otherwise I cannot explain why accept-range appeared, the cache plugin does not send other header than Cache-Status.
I have released a new version of the plugin which completely disables the cache when there is a partial response or the request has a range header. Please, let me know if that fixes your problem.
Fascinating; that must have happened just seconds after I restarted the server (this is very unlikely though, the site is extremely low traffic), because I went to try it literally just seconds after starting the server up. I'll try the new version and let you know!
@nicolasazrak The update seems to resolve the issue for me. Thanks! Still baffled, and frankly not convinced, that a request came in with such a range header, though.
On that note, does the cache consider request headers at all? (Since they can drastically change the content that gets served.) I know that response headers should dictate what to cache but I wonder what parts of the request are used to map requests to cache elements.
@mholt The cache only considers headers that the response specifies in vary header. Thinking about it in depth, I must also consider conditional headers like etag or If-Modified-Since. Are there any other headers that can affect the response and not appear in Vary?
Oh boy... I dunno tbh. Trial and error? Maybe looking at how nginx or varnish do it? (I don't have links for ya right now either, sorry...)