set-cookie-header
v0.0.1
Published
Decode and encode Set-Cookie headers
Downloads
98
Readme
set-cookie-header
Decode and encode
Set-Cookie
headers. Aligns with RFC6265.
Install
npm install set-cookie-header
Quick Start
import {encode, decode} from 'set-cookie-header';
const cookies = decode('foo=bar; Max-Age=1234; Domain=.example.com; Path=/; Expires=December 17, 1995 03:24:00 GMT; HttpOnly');
for (const cookie of cookies) {
cookie.secure = true;
const encoded = encoded(cookie);
}
API
decode(cookieHeader: string | string[]): Cookie[]
Accepts:
cookieHeader
can be a rawSet-Cookie
header, the value of the header, or an array of header values.- Eg:
'Set-Cookie: foo=bar; Path=/'
'foo=bar; Secure'
['foo=bar', 'biz=baz']
Returns:
- Array of decoded
Cookie
objects.
encode(cookie: Cookie | Cookie[]): string[]
Accepts:
- An array or a single
Cookie
object.
Returns:
- Array of encoded cookie strings.