Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixes handling of If-Modified-Since in combination with If-None-Match
  • Loading branch information
jonchurch authored Sep 9, 2024
1 parent accafc6 commit 4d713d2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion History.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
unreleased
=========================
* remove:
* remove:
- `path-is-absolute` dependency - use `path.isAbsolute` instead
* breaking:
* `res.status()` accepts only integers, and input must be greater than 99 and less than 1000
Expand All @@ -20,6 +20,7 @@ unreleased
* deps: type-is@^2.0.0
* deps: content-disposition@^1.0.0
* deps: finalhandler@^2.0.0
* deps: fresh@^2.0.0

5.0.0-beta.3 / 2024-03-25
=========================
Expand Down
2 changes: 1 addition & 1 deletion lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ defineGetter(req, 'hostname', function hostname(){

/**
* Check if the request is fresh, aka
* Last-Modified and/or the ETag
* Last-Modified or the ETag
* still match.
*
* @return {Boolean}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"finalhandler": "^2.0.0",
"fresh": "0.5.2",
"fresh": "2.0.0",
"http-errors": "2.0.0",
"merge-descriptors": "^2.0.0",
"methods": "~1.1.2",
Expand Down
20 changes: 20 additions & 0 deletions test/req.fresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,25 @@ describe('req', function(){
.get('/')
.expect(200, 'false', done);
})

it('should ignore "If-Modified-Since" when "If-None-Match" is present', function(done) {
var app = express();
const etag = '"FooBar"'
const now = Date.now()

app.disable('x-powered-by')
app.use(function(req, res) {
res.set('Etag', etag)
res.set('Last-Modified', new Date(now).toUTCString())
res.send(req.fresh);
});

request(app)
.get('/')
.set('If-Modified-Since', new Date(now - 1000).toUTCString)
.set('If-None-Match', etag)
.expect(304, done);
})

})
})

0 comments on commit 4d713d2

Please sign in to comment.