@fastify/cookie 9.0.3 → 9.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugin.js +5 -0
- package/test/cookie.test.js +22 -0
package/package.json
CHANGED
package/plugin.js
CHANGED
|
@@ -102,6 +102,11 @@ function setCookies (reply) {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
function fastifyCookieOnSendHandler (fastifyReq, fastifyRes, payload, done) {
|
|
105
|
+
if (!fastifyRes[kReplySetCookies]) {
|
|
106
|
+
done()
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
|
|
105
110
|
if (fastifyRes[kReplySetCookies].size) {
|
|
106
111
|
setCookies(fastifyRes)
|
|
107
112
|
}
|
package/test/cookie.test.js
CHANGED
|
@@ -1252,3 +1252,25 @@ test('cookies get set correctly if set inside onRequest', (t) => {
|
|
|
1252
1252
|
t.equal(cookies[0].path, '/')
|
|
1253
1253
|
})
|
|
1254
1254
|
})
|
|
1255
|
+
|
|
1256
|
+
test('do not crash if the onRequest hook is not run', (t) => {
|
|
1257
|
+
t.plan(3)
|
|
1258
|
+
const fastify = Fastify()
|
|
1259
|
+
fastify.addHook('onRequest', async (req, reply) => {
|
|
1260
|
+
return reply.send({ hello: 'world' })
|
|
1261
|
+
})
|
|
1262
|
+
|
|
1263
|
+
fastify.register(plugin)
|
|
1264
|
+
|
|
1265
|
+
fastify.inject({
|
|
1266
|
+
method: 'GET',
|
|
1267
|
+
url: '/test1',
|
|
1268
|
+
headers: {
|
|
1269
|
+
cookie: 'foo=foo'
|
|
1270
|
+
}
|
|
1271
|
+
}, (err, res) => {
|
|
1272
|
+
t.error(err)
|
|
1273
|
+
t.equal(res.statusCode, 200)
|
|
1274
|
+
t.same(JSON.parse(res.body), { hello: 'world' })
|
|
1275
|
+
})
|
|
1276
|
+
})
|