Skip to content

Commit

Permalink
Add partitioned option
Browse files Browse the repository at this point in the history
  • Loading branch information
pazguille authored and dougwilson committed Nov 7, 2023
1 parent c67a478 commit bcebc74
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
unreleased
==========

* Add `partitioned` option

0.5.0 / 2022-04-11
==================

Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ The given number will be converted to an integer by rounding down. By default, n
`maxAge` are set, then `maxAge` takes precedence, but it is possible not all clients by obey this,
so if both are set, they should point to the same date and time.

##### partitioned

Specifies the `boolean` value for the [`Partitioned` `Set-Cookie`](rfc-cutler-httpbis-partitioned-cookies)
attribute. When truthy, the `Partitioned` attribute is set, otherwise it is not. By default, the
`Partitioned` attribute is not set.

**note** This is an attribute that has not yet been fully standardized, and may change in the future.
This also means many clients may ignore this attribute until they understand it.

More information about can be found in [the proposal](https://github.com/privacycg/CHIPS).

##### path

Specifies the value for the [`Path` `Set-Cookie` attribute][rfc-6265-5.2.4]. By default, the path
Expand Down Expand Up @@ -275,6 +286,7 @@ $ npm run bench
- [RFC 6265: HTTP State Management Mechanism][rfc-6265]
- [Same-site Cookies][rfc-6265bis-09-5.4.7]

[rfc-cutler-httpbis-partitioned-cookies]: https://tools.ietf.org/html/draft-cutler-httpbis-partitioned-cookies/
[rfc-west-cookie-priority-00-4.1]: https://tools.ietf.org/html/draft-west-cookie-priority-00#section-4.1
[rfc-6265bis-09-5.4.7]: https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-09#section-5.4.7
[rfc-6265]: https://tools.ietf.org/html/rfc6265
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ function serialize(name, val, options) {
str += '; Secure';
}

if (opt.partitioned) {
str += '; Partitioned'
}

if (opt.priority) {
var priority = typeof opt.priority === 'string'
? opt.priority.toLowerCase()
Expand Down
14 changes: 14 additions & 0 deletions test/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ describe('cookie.serialize(name, value, options)', function () {
})
})

describe('with "partitioned" option', function () {
it('should include partitioned flag when true', function () {
assert.equal(cookie.serialize('foo', 'bar', { partitioned: true }), 'foo=bar; Partitioned')
})

it('should not include partitioned flag when false', function () {
assert.equal(cookie.serialize('foo', 'bar', { partitioned: false }), 'foo=bar')
})

it('should not include partitioned flag when not defined', function () {
assert.equal(cookie.serialize('foo', 'bar', {}), 'foo=bar')
})
})

describe('with "path" option', function () {
it('should serialize path', function () {
assert.equal(cookie.serialize('foo', 'bar', { path: '/' }), 'foo=bar; Path=/')
Expand Down

0 comments on commit bcebc74

Please sign in to comment.