Skip to content

fix: enable conditional revalidation (304) for QUERY requests#7376

Closed
ankit1324 wants to merge 1 commit into
expressjs:masterfrom
ankit1324:fix/query-method-freshness
Closed

fix: enable conditional revalidation (304) for QUERY requests#7376
ankit1324 wants to merge 1 commit into
expressjs:masterfrom
ankit1324:fix/query-method-freshness

Conversation

@ankit1324

Copy link
Copy Markdown

Fixes #7365

Problem

req.fresh (lib/request.js) short-circuits to false for any method other than GET/HEAD, so res.send/res.json never emit 304 Not Modified for a QUERY request even when the client sends a matching If-None-Match. QUERY is a safe, idempotent, cacheable method whose responses explicitly support conditional revalidation, so it should participate in freshness checks the same way GET/HEAD do.

Express already supports routing QUERY (#5615), and the test suite already has the shouldSkipQuery helper for running QUERY tests on Node >= 22 — this closes the freshness gap.

Change

Add QUERY to the method allowlist in the req.fresh getter. The 304 body-stripping path in res.send is 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 established shouldSkipQuery guard:

  • QUERY with matching If-None-Match → 304
  • QUERY with non-matching If-None-Match → 200 'false'

Full suite: 1260 passing, lint clean.

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

Copy link
Copy Markdown
Author

You're right @Cherry, apologies — I should have checked for existing PRs before opening this. #7366 is the same fix and predates mine, so closing in favor of yours. 👍

@ankit1324 ankit1324 closed this Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

req.fresh returns false for QUERY requests, so 304 Not Modified is never sent

1 participant