Skip to content
Myr

feat: allow conditional revalidation for QUERY requests (#7366)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* feat: allow conditional revalidation for QUERY requests 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. * docs: include history ---------

authored by James Ross · committed by GitHub · parent ba00676 · Browse files · 3 files+50 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Sebastian Beltran <bjohansebas@gmail.com>

Diff stats

3 files+50 added−2 removed

  • tests:+38 added−0 removed
  • other:+12 added−2 removed

3 files+50 added−2 removed

modified:lib/request.js+2 added-2 removed
469 unmodified lines
470 var method = this.method;471 var res = this.res472 var status = res.statusCode473474 // GET or HEAD for weak freshness validation only475 if ('GET' !== method && 'HEAD' !== method) return false;474 // GET, HEAD, or QUERY for weak freshness validation only475 if ('GET' !== method && 'HEAD' !== method && 'QUERY' !== method) return false;476477 // 2xx or 304 as per rfc2616 14.26478 if ((status >= 200 && status < 300) || 304 === status) {479 return fresh(this.headers, {
48 unmodified lines
modified:test/req.fresh.js+38 added
modified:History.md+10 added
7 unmodified lines
8 Fixed the behavior of `res.send()` to prevent conflicts between `Content-Length` and `Transfer-Encoding` HTTP headers in responses. The `Content-Length` header in `res.send()` is now only added when a `Transfer-Encoding` header is not present, complying with the HTTP specification that states both headers should not coexist in the same response910## 🚀 Improvements1112* Allow conditional revalidation for QUERY requests. `req.fresh` previously only validated freshness for GET and HEAD requests, so QUERY responses never returned 304 despite a matching validator. Since QUERY is a safe, idempotent, and cacheable method that supports conditional requests, it is now included in the freshness check - by [@Cherry](https://github.com/Cherry) in [#7366](https://github.com/expressjs/express/pull/7366)1314 ```js15 // QUERY /reports with If-None-Match: "12345"16 app.query('/reports', (req, res) => {17 res.set('ETag', '"12345"');18 res.send(results); // now responds 304 Not Modified19 });20 ```2122* Improve HTML structure in `res.redirect()` responses when HTML format is accepted by adding `<!DOCTYPE html>`, `<title>`, and `<body>` tags for better browser compatibility - by [@Bernice55231](https://github.com/Bernice55231) in [#5167](https://github.com/expressjs/express/pull/5167)2324* When calling `app.render` with options set to null, the locals object is handled correctly, preventing unexpected errors and making the method behave the same as when options is omitted or an empty object is passed - by [AkaHarshit](https://github.com/AkaHarshit) in [#6903](https://github.com/expressjs/express/pull/6903)25
3896 unmodified lines