Skip to content

feat: allow conditional revalidation for QUERY requests - #7366

Merged
bjohansebas merged 2 commits into
expressjs:masterfrom
Cherry:feat/fresh-query-method
Jul 12, 2026
Merged

feat: allow conditional revalidation for QUERY requests#7366
bjohansebas merged 2 commits into
expressjs:masterfrom
Cherry:feat/fresh-query-method

Conversation

@Cherry

@Cherry Cherry commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

req.fresh only performed weak freshness validation for GET and HEAD, so responses to QUERY requests never returned 304 Not Modified even when the client sent a matching If-None-Match. This extends the method guard to include QUERY.

-  // GET or HEAD for weak freshness validation only
-  if ('GET' !== method && 'HEAD' !== method) return false;
+  // GET, HEAD, or QUERY for weak freshness validation only
+  if ('GET' !== method && 'HEAD' !== method && 'QUERY' !== method) return false;

As far as I can tell, QUERY is a safe, idempotent, cacheable method whose responses explicitly support conditional revalidation, as per https://datatracker.ietf.org/doc/rfc10008/, so it should behave like GET/HEAD here.

I've added tests where it makes sense, and would also be happy to backport this to v4.x if accepted.

Fixes #7365

req.fresh only validated freshness for GET and HEAD, so QUERY responses never returned 304 despite a matching If-None-Match. QUERY is a safe, idempotent, cacheable method that supports conditional requests, so include it in the freshness check.
@krzysdz

krzysdz commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

cc @jonchurch (initial work on QUERY support) @blakeembrey (fresh captain)

@bjohansebas bjohansebas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

@bjohansebas bjohansebas added semver-patch This change is a semver patch and removed pr labels Jul 12, 2026
@bjohansebas
bjohansebas merged commit ae6dd37 into expressjs:master Jul 12, 2026
30 checks passed
@krzysdz

krzysdz commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

@bjohansebas is this really a feature or a bug fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5.x semver-patch This change is a semver patch

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

3 participants