Repository navigation
Leave unsafe-method responses alone and honor If-Range - #71
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.
Two correctness fixes. They are the parts of #70 worth keeping.
Conditional requests on state-changing methods. web evaluates
If-None-Matchafter the handler has run. For aPUT,POST,PATCHorDELETEthe write has already happened by then, and the response'sETagdescribes the new representation. A conditional create (PUTwithIf-None-Match: *) wrote and was then answered with a412, so the client was told its create failed after it succeeded. web now answers only aGETorHEADwith a304, and sends any other method's response as the handler built it. A handler that needs a precondition checks it before it acts, with http'sRequest.preconditionsagainst the resource's current validators. Nothing produces a412any more, soweb-precondition-failedis removed.If-Range. It was ignored. ARangerequest for a static file that had changed got a206with bytes of the new file, and a client resuming a download appended them to the old file's bytes.web-mark-rangenow arms the range only whenIf-Rangeis absent or names the current version, through http'sRequest.if-range-matches?. A weakETagnever matches (RFC 9110 §13.1.5). The check runs only for a static-file response to a request that carriesRange, and it reads the response's validators only whenIf-Rangeis present.Tests.
test/web.carpis 408/0 andtest/websocket.carpis 155/0, both with-Werror. The smoke test and gendocs pass.main, the 10 that pin the new behaviour fail, and the 5 that pin unchanged behaviour (a currentETagorLast-ModifiedinIf-Rangestill gets a206,If-RangewithoutRangeis ignored) pass.If-Rangegate fails 5 tests. Removing theGET/HEADgate fails 6.412's shape are removed, along withcors-conditional, which only they used.Cost. I timed
mainagainst this branch with 5,000 GETs throughweb-build-responseper run, over five request types (plain,If-None-Matchmiss and hit, browser revalidation,If-Modified-Sincehit), at-O0,-O1,-O2,-O3,-Osand--optimize, with five shuffled rounds. Every difference is within ±1.5% and inside the run-to-run spread of 1–4%, and the status codes are identical.carp-fmtchanges nothing on the lines this touches.