const headers = new Headers(init?: object | Array<[string, string]> | Headers);
Parameter | Type | Required | Description |
init | No | The HTTP header that is used to pre-populate the Headers object. Valid parameter types: object The Constructor API enumerates all enumerable attributes that are included in the specified object and pre-populates the attributes to the new Headers object. Array<[string, string]> Each element in the array is a key-value pair. Example: [key, value]. The Constructor API traverses the array and pre-populates the key-value pairs to the new Headers object. Headers The Constructor API copies all fields from an existing Headers object to the new Headers object. |
headers.append(name: string, value: string): void;
Headers
object. If the header does not exist, the append() method directly adds the header.Parameter | Type | Required | Description |
name | string | Yes | The name of the HTTP header that you want to add to the Headers object. |
value | string | Yes | The value of the HTTP header that you want to add. |
headers.delete(name: string): void;
Headers
object. Parameter | Type | Required | Description |
name | string | Yes | The name of the HTTP header that you want to delete from the Headers object. |
headers.entries(): iterator;
Headers
object. The key-value pairs are in the format of [name, value]. For valid return values, see Iteration protocols.headers.forEach(callback: (name: string, value: string) => void | number): void;
Headers
object. If callback
returns a non-zero value, traversal is stopped.forEach
method does not comply with Web API standards. Edge Functions extends the functionality of the method based on Web API standards to provide an efficient way to traverse headers.headers.get(name: string): string;
Headers
object.headers.getSetCookie(): Array<string>
headers.has(name: string): boolean;
Headers
object contains the specified header.headers.keys(): iterator;
Headers
object. For valid return values, see Iteration protocols.headers.set(name: string, value: string): void;
Headers
object. If the header does not exist, the set() method directly adds the header.headers.values(): iterator;
Headers
object. For valid return values, see Iteration protocols.function handleEvent() {const headers = new Headers({'my-header-x': 'hello world',});const response = new Response('hello world',{headers,});return response;}addEventListener('fetch', (event) => {event.respondWith(handleEvent(event));});
Was this page helpful?