Headers object
The Headers object is used to perform actions on request and response headers. Within a Headers object is a list of associated headers.
Syntax
var headers = new Headers(init);
Members
The Headers object has these types of members:
- Methods
Methods
The Headers object has these methods.
Method | Description |
---|---|
append | Appends a new value to an already existing header inside a Headers object. |
delete | Deletes a header from the current Headers object. |
get | Gets the first value of a header from the current Headers object. |
has | Checks whether or not a header exists within the current Headers object. |
set | Sets a new value to an already existing header inside a Headers object. |
Standards information
Remarks
The optional parameter of the Headers object can be used to populate it during creation. This can be either another Headers object, a sequence of ByteStrings, or an open-ended dictionary of ByteStrings.
The following snippet shows how a Headers object can be created with an open-ended dictionary:
var init = {"Content-Type": "text/html", "MyCustomHeader" : "value"};
var Headers(init);
Examples
The following example shows three Headers objects being created in different ways. The first Headers object takes a sequence of ByteStrings. The headers2
Headers object is given an open-ended dictionary. The last Headers object, header3
, populates by copying another Headers object's data.
var headers = new Headers([[“Content-Type”, “text/html”], [“MyCustomHeader”, ”value”]]);
var headers2 = new Headers({“Content-Type”: “text/html”, “MyCustomHeader”: ”value”});
var headers3 = new Headers(headers2);