From d765dde21c567df5b5667a08784000b714ae6c11 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Sun, 8 Dec 2024 09:15:49 +0100 Subject: [PATCH 1/2] correctly set if-none-match Signed-off-by: Matteo Collina --- lib/interceptor/cache.js | 2 +- test/interceptors/cache.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/interceptor/cache.js b/lib/interceptor/cache.js index e3fb202ad21..a60d92617ad 100644 --- a/lib/interceptor/cache.js +++ b/lib/interceptor/cache.js @@ -229,7 +229,7 @@ function handleResult ( } if (result.etag) { - headers.etag = result.etag + headers['if-none-match'] = result.etag } if (result.vary) { diff --git a/test/interceptors/cache.js b/test/interceptors/cache.js index 1b502c212b3..3ce271cc1ea 100644 --- a/test/interceptors/cache.js +++ b/test/interceptors/cache.js @@ -213,6 +213,7 @@ describe('Cache Interceptor', () => { let revalidationRequests = 0 let serverError const server = createServer((req, res) => { + console.log(req.headers) res.setHeader('date', 0) res.setHeader('cache-control', 's-maxage=1, stale-while-revalidate=10') From debd42ee1e88d30f4c9b7b4852730c98ff553b09 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Sun, 8 Dec 2024 09:33:03 +0100 Subject: [PATCH 2/2] added regression assertion Signed-off-by: Matteo Collina --- test/interceptors/cache.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/interceptors/cache.js b/test/interceptors/cache.js index 3ce271cc1ea..dc120c60b7b 100644 --- a/test/interceptors/cache.js +++ b/test/interceptors/cache.js @@ -155,6 +155,14 @@ describe('Cache Interceptor', () => { }).listen(0) const client = new Client(`http://localhost:${server.address().port}`) + .compose((dispatch) => { + return (opts, handler) => { + if (opts.headers) { + strictEqual(Object.prototype.hasOwnProperty.call(opts.headers, 'if-none-match'), false) + } + return dispatch(opts, handler) + } + }) .compose(interceptors.cache()) after(async () => { @@ -213,7 +221,6 @@ describe('Cache Interceptor', () => { let revalidationRequests = 0 let serverError const server = createServer((req, res) => { - console.log(req.headers) res.setHeader('date', 0) res.setHeader('cache-control', 's-maxage=1, stale-while-revalidate=10')