Repository navigation
Ignore Range in Plug.Static unless If-Range matches the ETag - #1337
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Plug.Staticserves aRangerequest without looking atIf-Range, so a client resuming a download of a file that has changed gets the requested bytes of the new file. For example, the first response's ETag is"A", the file is then replaced, and the client resumes withRange: bytes=500-andIf-Range: "A". It gets206with bytes 500 onwards of the new content and stitches them onto the old first half.RFC 9110 section 13.1.5 says the server must ignore
Rangewhen theIf-Rangevalidator does not match. A matching validator is an entity tag that equals the current ETag under the strong comparison, or a date that equalsLast-Modified.serve_range/5now only uses the range when there is noIf-Range, or whenIf-Rangeis the response's ETag and that ETag is not weak. Otherwise it sends the whole file with200, as it already does for a range it can't serve. A date never matches becausePlug.Staticdoesn't sendLast-Modified. This also applies when the response has no ETag at all, forvsnrequests or whencache_control_for_etagsisnil.The new tests in the "range request" block check:
If-Rangewith the current ETag still gets206.200with the full body. This holds for a satisfiable range and for one that would otherwise be a416.If-Rangeon avsnrequest, which has no ETag, gets200.Without the change, the first mismatch case gets
206and the test fails. With it,mix testpasses (617 tests) andmix format --check-formattedis clean.