diff --git a/lib/send.js b/lib/send.js index 645e766..eac99b1 100644 --- a/lib/send.js +++ b/lib/send.js @@ -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 } } diff --git a/test/send.2.test.js b/test/send.2.test.js index 957d6f5..b7ef988 100644 --- a/test/send.2.test.js +++ b/test/send.2.test.js @@ -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) { @@ -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) {