From 269591f019b2a9991b6e88927fc298c8228df691 Mon Sep 17 00:00:00 2001 From: James Sumners Date: Sun, 5 Jan 2020 16:48:17 -0500 Subject: [PATCH 1/3] Failing test --- test/cookie.test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/cookie.test.js b/test/cookie.test.js index 7d2ab2e..9254029 100644 --- a/test/cookie.test.js +++ b/test/cookie.test.js @@ -312,3 +312,27 @@ test('pass options to `cookies.parse`', (t) => { return str + 'test' } }) + +test('issue 53', async t => { + const fastify = Fastify() + fastify.register(plugin) + + let cookies + let count = 1 + fastify.get('/foo', (req, reply) => { + if (count > 1) { + t.notEqual(cookies, req.cookies) + return reply.send('done') + } + + count += 1 + cookies = req.cookies + reply.send('done') + }) + + const response1 = await fastify.inject({ url: '/foo' }) + t.is(response1.body, 'done') + + const response2 = await fastify.inject({ url: '/foo' }) + t.is(response2.body, 'done') +}) From 09cc46a30c80c2b75d6ca0fe63cfcc74e06767d7 Mon Sep 17 00:00:00 2001 From: James Sumners Date: Sun, 5 Jan 2020 16:49:19 -0500 Subject: [PATCH 2/3] Fix issue #53 --- plugin.js | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin.js b/plugin.js index 9ff0f8a..8417335 100644 --- a/plugin.js +++ b/plugin.js @@ -38,6 +38,7 @@ function fastifyCookieClearCookie (reply, name, options) { function onReqHandlerWrapper (options) { return function fastifyCookieOnReqHandler (fastifyReq, fastifyRes, done) { + fastifyReq.cookies = {} // New container per request. Issue #53 const cookieHeader = fastifyReq.req.headers.cookie if (cookieHeader) { fastifyReq.cookies = cookie.parse(cookieHeader, options) From 3e92f2f395ab0b1554cba0e658c8066755349f36 Mon Sep 17 00:00:00 2001 From: James Sumners Date: Sun, 5 Jan 2020 16:52:53 -0500 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=98=9E=20Node=206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/cookie.test.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/cookie.test.js b/test/cookie.test.js index 9254029..7fe8336 100644 --- a/test/cookie.test.js +++ b/test/cookie.test.js @@ -313,7 +313,8 @@ test('pass options to `cookies.parse`', (t) => { } }) -test('issue 53', async t => { +test('issue 53', (t) => { + t.plan(5) const fastify = Fastify() fastify.register(plugin) @@ -330,9 +331,13 @@ test('issue 53', async t => { reply.send('done') }) - const response1 = await fastify.inject({ url: '/foo' }) - t.is(response1.body, 'done') + fastify.inject({ url: '/foo' }, (err, response) => { + t.error(err) + t.is(response.body, 'done') + }) - const response2 = await fastify.inject({ url: '/foo' }) - t.is(response2.body, 'done') + fastify.inject({ url: '/foo' }, (err, response) => { + t.error(err) + t.is(response.body, 'done') + }) })