Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@ function isNotModifiedFailure (request, headers) {
const ifModifiedSince = request.headers['if-modified-since']
const lastModified = headers['Last-Modified']

if (!lastModified || (Date.parse(lastModified) <= Date.parse(ifModifiedSince))) {
// Without a Last-Modified header there is nothing to compare against,
// so the response is considered stale.
if (lastModified && Date.parse(lastModified) <= Date.parse(ifModifiedSince)) {
return true
}
}
Expand Down
16 changes: 15 additions & 1 deletion test/send.2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ test('send(file)', async function (t) {
})

await t.test('where "If-Modified-Since" is set', async function (t) {
t.plan(3)
t.plan(4)

await t.test('should respond with 304 when unmodified', async function (t) {
const app = http.createServer(async function (req, res) {
Expand Down Expand Up @@ -459,6 +459,20 @@ test('send(file)', async function (t) {
.set('cache-control', 'no-cache')
.expect(200, 'tobi')
})

await t.test('should respond with 200 when Last-Modified is disabled', async function (t) {
const app = http.createServer(async function (req, res) {
const { statusCode, headers, stream } = await send(req, req.url, { root: fixtures, lastModified: false })
res.writeHead(statusCode, headers)
stream.pipe(res)
})

await request(app)
.get('/name.txt')
.set('If-Modified-Since', new Date(0).toUTCString())
.expect(shouldNotHaveHeader('Last-Modified', t))
.expect(200, 'tobi')
})
})

await t.test('where "If-None-Match" is set', async function (t) {
Expand Down
Loading