Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = class Cookie {
this.domain = cookie.domain || null
this.httpOnly = cookie.httpOnly !== undefined ? cookie.httpOnly : true
this.partitioned = cookie.partitioned
this.priority = cookie.priority
this._expires = null

if (cookie.expires) {
Expand Down Expand Up @@ -66,7 +67,8 @@ module.exports = class Cookie {
path: this.path,
httpOnly: this.httpOnly,
domain: this.domain,
partitioned: this.partitioned
partitioned: this.partitioned,
priority: this.priority
}
}
}
21 changes: 21 additions & 0 deletions test/cookie.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,27 @@ test('should set session partitioned cookie secure http encrypted', async (t) =>
t.assert.strictEqual(new RegExp(pattern).test(response.headers['set-cookie']), true)
})

test('should set session cookie with priority', async (t) => {
t.plan(2)
const options = {
secret: DEFAULT_SECRET,
cookie: { priority: 'high', secure: false }
}
const fastify = await buildFastify((request, reply) => {
request.session.test = {}
reply.send(200)
}, options)
t.after(() => { fastify.close() })

const response = await fastify.inject({
url: '/'
})

t.assert.strictEqual(response.statusCode, 200)
const pattern = String.raw`sessionId=${SIGNED_COOKIE_VALUE_PATTERN}; Path=\/; HttpOnly; Priority=High`
t.assert.strictEqual(new RegExp(pattern).test(response.headers['set-cookie']), true)
})

test('should use maxAge instead of expires in session if both are set in options.cookie', async (t) => {
t.plan(3)
const expires = new Date(34214461000) // 1971-02-01T00:01:01.000Z
Expand Down