From c6541c1e7a3a656bfab648677b7fdc68a8bf17c4 Mon Sep 17 00:00:00 2001 From: Bono Stebler Date: Tue, 20 Jan 2015 21:27:26 +0100 Subject: [PATCH 1/3] sendResponse() will now reply with a 304 if the Etag matches the request's If-None-Match header --- index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index a0d8d9e..b79a050 100644 --- a/index.js +++ b/index.js @@ -220,9 +220,15 @@ module.exports = function enchilada(opt) { } res.setHeader('Content-Type', 'application/javascript'); - res.setHeader('ETag', crypto.createHash('md5').update(src).digest('hex').slice(0, 6)); - res.setHeader('Vary', 'Accept-Encoding'); - respond(200, src); + + var etag = crypto.createHash('md5').update(src).digest('hex').slice(0, 6); + if (etag === req.get('If-None-Match')) { + respond(304, ''); + }else{ + res.setHeader('ETag', etag); + res.setHeader('Vary', 'Accept-Encoding'); + respond(200, src); + } } function sendError(err) { From 225108ba054161ae86c37ed3b15beea8986bc25d Mon Sep 17 00:00:00 2001 From: Bono Stebler Date: Tue, 20 Jan 2015 21:47:31 +0100 Subject: [PATCH 2/3] Fixed checking for request header without Express --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index b79a050..1e5eab9 100644 --- a/index.js +++ b/index.js @@ -222,7 +222,7 @@ module.exports = function enchilada(opt) { res.setHeader('Content-Type', 'application/javascript'); var etag = crypto.createHash('md5').update(src).digest('hex').slice(0, 6); - if (etag === req.get('If-None-Match')) { + if (req.get && (etag === req.get('If-None-Match'))) { respond(304, ''); }else{ res.setHeader('ETag', etag); From c9adb9ec256333401dcbc441f27b4cd674c1f07a Mon Sep 17 00:00:00 2001 From: Bono Stebler Date: Wed, 21 Jan 2015 03:08:23 +0100 Subject: [PATCH 3/3] Corrected code style --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 1e5eab9..d9b3f47 100644 --- a/index.js +++ b/index.js @@ -224,7 +224,8 @@ module.exports = function enchilada(opt) { var etag = crypto.createHash('md5').update(src).digest('hex').slice(0, 6); if (req.get && (etag === req.get('If-None-Match'))) { respond(304, ''); - }else{ + } + else { res.setHeader('ETag', etag); res.setHeader('Vary', 'Accept-Encoding'); respond(200, src);