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 1600888
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
@@ -1,3 +1,8 @@
unreleased
==========

* Add `partitioned` option

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

Expand Down
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -150,6 +150,15 @@ the `Secure` attribute is set, otherwise it is not. By default, the `Secure` att
**note** be careful when setting this to `true`, as compliant clients will not send the cookie back to
the server in the future if the browser does not have an HTTPS connection.

##### partitioned

Specifies the `boolean` value for the [`Partitioned` `Set-Cookie`](draft-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).

## Example

The following example uses this module in conjunction with the Node.js core HTTP server
Expand Down Expand Up @@ -286,6 +295,7 @@ $ npm run bench
[rfc-6265-5.2.5]: https://tools.ietf.org/html/rfc6265#section-5.2.5
[rfc-6265-5.2.6]: https://tools.ietf.org/html/rfc6265#section-5.2.6
[rfc-6265-5.3]: https://tools.ietf.org/html/rfc6265#section-5.3
[draft-cutler-httpbis-partitioned-cookies]: https://datatracker.ietf.org/doc/html/draft-cutler-httpbis-partitioned-cookies/

## License

Expand Down
4 changes: 4 additions & 0 deletions index.js
Expand Up @@ -214,6 +214,10 @@ function serialize(name, val, options) {
}
}

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

return str;
}

Expand Down
14 changes: 14 additions & 0 deletions test/serialize.js
Expand Up @@ -193,4 +193,18 @@ describe('cookie.serialize(name, value, options)', function () {
assert.equal(cookie.serialize('foo', 'bar', { secure: false }), 'foo=bar')
})
})

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')
})
})
})

0 comments on commit 1600888

Please sign in to comment.