Repository navigation
Conversation
This branch has not been deployed
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.
In #116 the 304 handling was described as matching Express' etag middleware. In practice it differs in a few places. With
fastify.register(etag)and a route that returns'hello'(also mounted as a POST route, and as a GET route that setsreply.code(404)), compared with Express' default ETag andreq.fresh:GET,If-None-Match: <tag>GET,If-None-Match: "x", <tag>GET,If-None-Match: *POST,If-None-Match: <tag>GETon the 404 route,If-None-Match: <tag>The hook compared the header to the ETag as a single string, and it did so for any method and any status code. Express'
req.freshonly considersGET/HEADwith a 2xx (or 304) response, andfreshtreatsIf-None-Matchas a list of entity tags (plus*) with the weak comparison from RFC 9110 §13.1.2. The last two rows are the more visible ones: a POST, or an error response whose body happens to hash to the client's cached tag, is turned into an empty 304.This adds an
isFresh()helper with those same conditions. The existing weak/strong combinations behave as before, because both sides go through the sameW/stripping.Tests: five cases in
test/generic.js(a match inside a list, a list with no match,*, POST, a 404 route), run for each algorithm. 25 of them fail without the change.npm test(100% coverage, tstyche) andnpm run lintpass. I also updated the README sentence that describes when a 304 is sent.