Skip to content
This repository has been archived by the owner on Apr 18, 2021. It is now read-only.

Cached images only downloading last byte #17

Open
mholt opened this issue Aug 1, 2017 · 8 comments
Open

Cached images only downloading last byte #17

mholt opened this issue Aug 1, 2017 · 8 comments

Comments

@mholt
Copy link

mholt commented Aug 1, 2017

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.

@dusty
Copy link

dusty commented Aug 1, 2017

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.

@nicolasazrak
Copy link
Owner

nicolasazrak commented Aug 1, 2017

@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.

@mholt
Copy link
Author

mholt commented Aug 1, 2017

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.

@nicolasazrak
Copy link
Owner

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.

@mholt
Copy link
Author

mholt commented Aug 2, 2017

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!

@mholt
Copy link
Author

mholt commented Aug 2, 2017

@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.

@nicolasazrak
Copy link
Owner

@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?

@mholt
Copy link
Author

mholt commented Aug 5, 2017

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...)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants