name + domain + path. You can manage Cookies objects based on the unique keys.const cookies = new Cookies(cookieStr?: string, isSetCookie?: boolean);
Parameter | Type | Required | Description |
cookieStr | string | No | |
isSetCookie | boolean | No | Specifies whether the value of the cookieStr parameter is a Set-Cookie string. Default value: false. |
cookies.get(name?: string): null | Cookie | Array<Cookie>;
Parameter | Type | Required | Description |
name | string | No | The name of Cookie object. Valid options: Default name Obtains all Cookie objects. Specified name Obtains the Cookie object of the specified name. If multiple objects are matched, a Cookie array is returned. |
Cookie object. For more information, see Set-Cookie.Attribute | Type | Read-only | Description |
name | string | Yes | The name of the Cookie object. |
value | string | Yes | The value of the Cookie object. |
domain | string | Yes | The host to which the Cookie object will be sent. |
path | string | Yes | The path to which the Cookie object will be sent. |
expires | string | Yes | |
max_age | string | Yes | The number of seconds until the Cookie object expires. |
samesite | string | Yes | Controls whether the Cookie object is sent with cross-site requests, providing some protection against cross-site request forgery (CSRF) attacks. |
httponly | boolean | Yes | Forbids JavaScript from accessing the Cookie object. The attribute is carried only by HTTP requests. |
secure | boolean | Yes | Specifies that the Cookie object can be carried only by HTTPS requests. |
cookies.set(name: string, value: string, options?: Cookie): boolean;
true is returned, cookies are successfully added. If false is returned, cookies fail to be added because the number of cookies exceeds the upper limit. For more information, see Cookie limits.name + domain + path.Parameter | Type | Required | Description |
name | string | Yes | The name of the Cookie object. |
value | string | Yes | The value of the Cookie object. |
Cookie | string | No |
cookies.append(name: string, value: string, options?: Cookie): boolean;
true is returned, cookies are successfully appended. If false is returned, cookies fail to be appended because the value already exists or the number of cookies exceeds the upper limit. For more information, see Cookie limits.name + domain + path.cookies.remove(name: string, options?: Cookie): boolean;
name + domain + path.name attribute: " ( ) , / : ; ? < = > ? @ [ ] \\ { }. 0x00~0x1F and 0x7F~0xFF.value attribute: , , ; " \\. 0x00~0x1F and 0x7F~0xFF.name cannot exceed 64 bytes.value, domain, path, expires, max_age, and samesite cannot exceed 1 KB.function handleEvent(event) {const response = new Response('hello world');// Generate a Cookies object.const cookies = new Cookies('ssid=helloworld; expires=Sun, 10-Dec-2023 03:10:01 GMT; path=/; domain=.tencentcloud.com; samesite=.tencentcloud.com', true);// Set the response header Set-Cookie.response.setCookies(cookies);return response;}addEventListener('fetch', (event) => {event.respondWith(handleEvent(event));});
Feedback