diff --git a/HISTORY.md b/HISTORY.md index 1748679..b7271e4 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +unreleased +========== + + * Add `partitioned` option + 0.5.0 / 2022-04-11 ================== diff --git a/README.md b/README.md index 5449c3a..a489092 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/index.js b/index.js index 12128b9..fcd0111 100644 --- a/index.js +++ b/index.js @@ -214,6 +214,10 @@ function serialize(name, val, options) { } } + if (opt.partitioned) { + str += '; Partitioned' + } + return str; } diff --git a/test/serialize.js b/test/serialize.js index 6e34590..41c3ff5 100644 --- a/test/serialize.js +++ b/test/serialize.js @@ -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') + }) + }) })