fix: enable conditional revalidation (304) for QUERY requests#7376
Closed
ankit1324 wants to merge 1 commit into
Closed
fix: enable conditional revalidation (304) for QUERY requests#7376ankit1324 wants to merge 1 commit into
ankit1324 wants to merge 1 commit into
Conversation
req.fresh short-circuited to false for any method other than GET/HEAD, so res.send/res.json never emitted 304 Not Modified for a QUERY request even when the client sent a matching If-None-Match. QUERY is a safe, idempotent, cacheable method whose responses support conditional revalidation, so it should participate in freshness checks like GET/HEAD. fixes expressjs#7365
Author
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.
Fixes #7365
Problem
req.fresh(lib/request.js) short-circuits tofalsefor any method other thanGET/HEAD, sores.send/res.jsonnever emit304 Not Modifiedfor aQUERYrequest even when the client sends a matchingIf-None-Match. QUERY is a safe, idempotent, cacheable method whose responses explicitly support conditional revalidation, so it should participate in freshness checks the same wayGET/HEADdo.Express already supports routing QUERY (#5615), and the test suite already has the
shouldSkipQueryhelper for running QUERY tests on Node >= 22 — this closes the freshness gap.Change
Add
QUERYto the method allowlist in thereq.freshgetter. The 304 body-stripping path inres.sendis method-agnostic, so no other changes are needed.Tests
Two new cases in
test/req.fresh.js, mirroring the existing GET cases and using the establishedshouldSkipQueryguard:If-None-Match→ 304If-None-Match→ 200'false'Full suite: 1260 passing, lint clean.