From 84a156749b673dbfbf43679829b15be09fbd8988 Mon Sep 17 00:00:00 2001 From: pazguille Date: Wed, 30 Aug 2023 20:54:56 -0300 Subject: [PATCH] Add partitioned option closes #147 closes #151 closes #153 --- HISTORY.md | 5 +++++ README.md | 12 ++++++++++++ index.js | 4 ++++ test/serialize.js | 14 ++++++++++++++ 4 files changed, 35 insertions(+) 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..9b98434 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/index.js b/index.js index 12128b9..03d4c38 100644 --- a/index.js +++ b/index.js @@ -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() diff --git a/test/serialize.js b/test/serialize.js index 6e34590..80d0c48 100644 --- a/test/serialize.js +++ b/test/serialize.js @@ -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=/')