Skip to content

Commit 3ee08c4

Browse files
mlucooldougwilson
authored andcommitted
Add "priority" to cookie options
closes #884 closes #939
1 parent 71c3f74 commit 3ee08c4

File tree

6 files changed

+46
-9
lines changed

6 files changed

+46
-9
lines changed

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
unreleased
22
==========
33

4+
* Add `priority` to `cookie` options
45
* Support any type in `secret` that `crypto.createHmac` supports
6+
7+
- Fix `expires` option to reject invalid dates
8+
- perf: improve default decode speed
9+
- perf: remove slow string split in parse
510
611

712
1.17.3 / 2022-05-11

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ defined in the object is what is used.
9494
Specifies the value for the `Path` `Set-Cookie`. By default, this is set to `'/'`, which
9595
is the root path of the domain.
9696

97+
##### cookie.priority
98+
99+
Specifies the `string` to be the value for the [`Priority` `Set-Cookie` attribute][rfc-west-cookie-priority-00-4.1].
100+
101+
- `'low'` will set the `Priority` attribute to `Low`.
102+
- `'medium'` will set the `Priority` attribute to `Medium`, the default priority when not set.
103+
- `'high'` will set the `Priority` attribute to `High`.
104+
105+
More information about the different priority levels can be found in
106+
[the specification][rfc-west-cookie-priority-00-4.1].
107+
108+
**Note** This is an attribute that has not yet been fully standardized, and may change in the future.
109+
This also means many clients may ignore this attribute until they understand it.
110+
97111
##### cookie.sameSite
98112

99113
Specifies the `boolean` or `string` to be the value for the `SameSite` `Set-Cookie` attribute.
@@ -994,6 +1008,7 @@ On Windows, use the corresponding command;
9941008
[MIT](LICENSE)
9951009

9961010
[rfc-6265bis-03-4.1.2.7]: https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7
1011+
[rfc-west-cookie-priority-00-4.1]: https://tools.ietf.org/html/draft-west-cookie-priority-00#section-4.1
9971012
[ci-image]: https://badgen.net/github/checks/expressjs/session/master?label=ci
9981013
[ci-url]: https://github.com/expressjs/session/actions?query=workflow%3Aci
9991014
[coveralls-image]: https://badgen.net/coveralls/c/github/expressjs/session/master

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"repository": "expressjs/session",
1111
"license": "MIT",
1212
"dependencies": {
13-
"cookie": "0.4.2",
13+
"cookie": "0.5.0",
1414
"cookie-signature": "1.0.7",
1515
"debug": "2.6.9",
1616
"depd": "~2.0.0",

session/cookie.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ Cookie.prototype = {
116116

117117
get data() {
118118
return {
119-
originalMaxAge: this.originalMaxAge
119+
originalMaxAge: this.originalMaxAge,
120+
priority: this.priority
120121
, expires: this._expires
121122
, secure: this.secure
122123
, httpOnly: this.httpOnly

test/cookie.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,13 @@ describe('new Cookie()', function () {
114114
assert.strictEqual(cookie.path, '/foo')
115115
})
116116
})
117+
118+
describe('priority', function () {
119+
it('should set priority', function () {
120+
var cookie = new Cookie({ priority: 'high' })
121+
122+
assert.strictEqual(cookie.priority, 'high')
123+
})
124+
})
117125
})
118126
})

test/session.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,18 +1923,26 @@ describe('session()', function(){
19231923
})
19241924

19251925
it('should override defaults', function(done){
1926-
var server = createServer({ cookie: { path: '/admin', httpOnly: false, secure: true, maxAge: 5000 } }, function (req, res) {
1926+
var opts = {
1927+
httpOnly: false,
1928+
maxAge: 5000,
1929+
path: '/admin',
1930+
priority: 'high',
1931+
secure: true
1932+
}
1933+
var server = createServer({ cookie: opts }, function (req, res) {
19271934
req.session.cookie.secure = false
19281935
res.end()
19291936
})
19301937

19311938
request(server)
1932-
.get('/admin')
1933-
.expect(shouldSetCookieWithAttribute('connect.sid', 'Expires'))
1934-
.expect(shouldSetCookieWithoutAttribute('connect.sid', 'HttpOnly'))
1935-
.expect(shouldSetCookieWithAttributeAndValue('connect.sid', 'Path', '/admin'))
1936-
.expect(shouldSetCookieWithoutAttribute('connect.sid', 'Secure'))
1937-
.expect(200, done)
1939+
.get('/admin')
1940+
.expect(shouldSetCookieWithAttribute('connect.sid', 'Expires'))
1941+
.expect(shouldSetCookieWithoutAttribute('connect.sid', 'HttpOnly'))
1942+
.expect(shouldSetCookieWithAttributeAndValue('connect.sid', 'Path', '/admin'))
1943+
.expect(shouldSetCookieWithoutAttribute('connect.sid', 'Secure'))
1944+
.expect(shouldSetCookieWithAttributeAndValue('connect.sid', 'Priority', 'High'))
1945+
.expect(200, done)
19381946
})
19391947

19401948
it('should preserve cookies set before writeHead is called', function(done){

0 commit comments

Comments
 (0)