Skip to content

Commit

Permalink
Merge pull request #54 from fastify/issue-53
Browse files Browse the repository at this point in the history
Fix issue 53
  • Loading branch information
jsumners authored Jan 5, 2020
2 parents 6cdc377 + 3e92f2f commit e0083ba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions test/cookie.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,32 @@ test('pass options to `cookies.parse`', (t) => {
return str + 'test'
}
})

test('issue 53', (t) => {
t.plan(5)
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')
})

fastify.inject({ url: '/foo' }, (err, response) => {
t.error(err)
t.is(response.body, 'done')
})

fastify.inject({ url: '/foo' }, (err, response) => {
t.error(err)
t.is(response.body, 'done')
})
})

0 comments on commit e0083ba

Please sign in to comment.