@arcjet/headers
Advanced tools
+33
-22
@@ -0,35 +1,46 @@ | ||
| type HeadersInit = Headers | Array<[string, string]> | Record<string, Array<string> | string | undefined>; | ||
| /** | ||
| * This Fetch API interface allows you to perform various actions on HTTP | ||
| * request and response headers. These actions include retrieving, setting, | ||
| * adding to, and removing. A Headers object has an associated header list, | ||
| * which is initially empty and consists of zero or more name and value pairs. | ||
| * Arcjet headers. | ||
| * | ||
| * You can add to this using methods like `append()`. | ||
| * This exists to prevent the `cookie` header from being set | ||
| * and non-string values from being set. | ||
| * | ||
| * In all methods of this interface, header names are matched by | ||
| * case-insensitive byte sequence. | ||
| * | ||
| * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Headers) | ||
| * @see | ||
| * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Headers). | ||
| */ | ||
| export default class ArcjetHeaders extends Headers { | ||
| constructor(init?: HeadersInit | Record<string, string | string[] | undefined>); | ||
| export declare class ArcjetHeaders extends Headers { | ||
| constructor(init?: HeadersInit | undefined); | ||
| /** | ||
| * Append a key and value to the headers, while filtering any key named | ||
| * `cookie`. | ||
| * Append a header while ignoring `cookie`. | ||
| * | ||
| * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Headers/append) | ||
| * @see | ||
| * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Headers/append) | ||
| * | ||
| * @param key The key to append in the headers | ||
| * @param value The value to append for the key in the headers | ||
| * @param key | ||
| * Header name. | ||
| * @param value | ||
| * Header value. | ||
| * @returns | ||
| * Nothing. | ||
| */ | ||
| append(key: string, value: string): void; | ||
| append: (key: string, value: string) => void; | ||
| /** | ||
| * Set a key and value in the headers, but filtering any key named `cookie`. | ||
| * Set a header while ignoring `cookie`. | ||
| * | ||
| * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Headers/set) | ||
| * @see | ||
| * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Headers/set) | ||
| * | ||
| * @param key The key to set in the headers | ||
| * @param value The value to set for the key in the headers | ||
| * @param key | ||
| * Header key. | ||
| * @param value | ||
| * Header value. | ||
| * @returns | ||
| * Nothing. | ||
| */ | ||
| set(key: string, value: string): void; | ||
| set: (key: string, value: string) => void; | ||
| } | ||
| /** | ||
| * @deprecated | ||
| * Use the named export `ArcjetHeaders` instead. | ||
| */ | ||
| export default ArcjetHeaders; |
+30
-25
@@ -5,13 +5,9 @@ function isIterable(val) { | ||
| /** | ||
| * This Fetch API interface allows you to perform various actions on HTTP | ||
| * request and response headers. These actions include retrieving, setting, | ||
| * adding to, and removing. A Headers object has an associated header list, | ||
| * which is initially empty and consists of zero or more name and value pairs. | ||
| * Arcjet headers. | ||
| * | ||
| * You can add to this using methods like `append()`. | ||
| * This exists to prevent the `cookie` header from being set | ||
| * and non-string values from being set. | ||
| * | ||
| * In all methods of this interface, header names are matched by | ||
| * case-insensitive byte sequence. | ||
| * | ||
| * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Headers) | ||
| * @see | ||
| * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Headers). | ||
| */ | ||
@@ -47,11 +43,15 @@ class ArcjetHeaders extends Headers { | ||
| /** | ||
| * Append a key and value to the headers, while filtering any key named | ||
| * `cookie`. | ||
| * Append a header while ignoring `cookie`. | ||
| * | ||
| * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Headers/append) | ||
| * @see | ||
| * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Headers/append) | ||
| * | ||
| * @param key The key to append in the headers | ||
| * @param value The value to append for the key in the headers | ||
| * @param key | ||
| * Header name. | ||
| * @param value | ||
| * Header value. | ||
| * @returns | ||
| * Nothing. | ||
| */ | ||
| append(key, value) { | ||
| append = (key, value) => { | ||
| if (typeof key !== "string" || typeof value !== "string") { | ||
@@ -61,14 +61,19 @@ return; | ||
| if (key.toLowerCase() !== "cookie") { | ||
| super.append(key, value); | ||
| Headers.prototype.append.call(this, key, value); | ||
| } | ||
| } | ||
| }; | ||
| /** | ||
| * Set a key and value in the headers, but filtering any key named `cookie`. | ||
| * Set a header while ignoring `cookie`. | ||
| * | ||
| * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Headers/set) | ||
| * @see | ||
| * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Headers/set) | ||
| * | ||
| * @param key The key to set in the headers | ||
| * @param value The value to set for the key in the headers | ||
| * @param key | ||
| * Header key. | ||
| * @param value | ||
| * Header value. | ||
| * @returns | ||
| * Nothing. | ||
| */ | ||
| set(key, value) { | ||
| set = (key, value) => { | ||
| if (typeof key !== "string" || typeof value !== "string") { | ||
@@ -78,7 +83,7 @@ return; | ||
| if (key.toLowerCase() !== "cookie") { | ||
| super.set(key, value); | ||
| Headers.prototype.set.call(this, key, value); | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| export { ArcjetHeaders as default }; | ||
| export { ArcjetHeaders, ArcjetHeaders as default }; |
+6
-7
| { | ||
| "name": "@arcjet/headers", | ||
| "version": "1.0.0-beta.10", | ||
| "version": "1.0.0-beta.11", | ||
| "description": "Arcjet extension of the Headers class", | ||
@@ -47,8 +47,7 @@ "keywords": [ | ||
| "devDependencies": { | ||
| "@arcjet/eslint-config": "1.0.0-beta.10", | ||
| "@arcjet/rollup-config": "1.0.0-beta.10", | ||
| "@arcjet/tsconfig": "1.0.0-beta.10", | ||
| "@rollup/wasm-node": "4.46.2", | ||
| "@types/node": "18.18.0", | ||
| "eslint": "9.32.0", | ||
| "@arcjet/eslint-config": "1.0.0-beta.11", | ||
| "@arcjet/rollup-config": "1.0.0-beta.11", | ||
| "@rollup/wasm-node": "4.50.0", | ||
| "@types/node": "24.3.0", | ||
| "eslint": "9.34.0", | ||
| "typescript": "5.9.2" | ||
@@ -55,0 +54,0 @@ }, |
+1
-1
@@ -47,3 +47,3 @@ <a href="https://arcjet.com" target="_arcjet-home"> | ||
| ```ts | ||
| import ArcjetHeaders from "@arcjet/headers"; | ||
| import { ArcjetHeaders } from "@arcjet/headers"; | ||
@@ -50,0 +50,0 @@ const headers = new ArcjetHeaders({ abc: "123" }); |
6
-14.29%130
14.04%18216
-2.88%