Wearable Only
Append a new value onto an existing header inside a Headers object, or adds the header if it does not already exist.
The difference between set() and append() is that if the specified header already exists and accepts multiple values, set() will overwrite the existing value with the new one, whereas append() will append the new value onto the end of the set of values.
myHeaders.append("Accept-Encoding", "deflate");
myHeaders.append("Accept-Encoding", "gzip");
myHeaders.get("Accept-Encoding"); // Returns 'deflate, gzip'
Deletes a header from the Headers object.
myHeaders.append("Content-Type", "image/jpeg");
myHeaders.get("Content-Type"); // Returns 'image/jpeg'
myHeaders.delete("Content-Type");
myHeaders.get("Content-Type"); // Returns null, as it has been deleted
Returns an iterator allowing to go through all key/value pairs contained in this object. Both the key and value of each pair are String objects.
// Print the key/value pairs
for (const pair of myHeaders.entries()) {
print(`${pair[0]}: ${pair[1]}`);
}
Returns a comma-separated string of all the values of a header within a Headers object with a given name. If the requested header doesn't exist in the Headers object, returns null.
myHeaders.append("Accept-Encoding", "deflate");
myHeaders.append("Accept-Encoding", "gzip");
myHeaders.get("Accept-Encoding"); // Returns "deflate, gzip"
Returns the name of this object's type.
Returns a boolean stating whether the Headers object contains the given header.
Returns true if the object matches or derives from the passed in type.
Returns true if this object is the same as other
. Useful for checking if two references point to the same thing.
Returns an iterator allowing you to go through all keys contained in the Headers. The keys are String objects.
// Print the keys
for (const key of myHeaders.keys()) {
print(key);
}
Sets a new value for an existing header inside a Headers object, or adds the header if it does not already exist.
The difference between set() and Headers.append is that if the specified header already exists and accepts multiple values, set() overwrites the existing value with the new one, whereas Headers.append appends the new value to the end of the set of values.
myHeaders.set("Accept-Encoding", "deflate");
myHeaders.set("Accept-Encoding", "gzip");
myHeaders.get("Accept-Encoding"); // Returns 'gzip'
Returns an iterator allowing you to go through all values contained in the Headers. The values are String objects.
// Print the values
for (const value of myHeaders.values()) {
print(value);
}
Headers for the Fetch API in RemoteServiceModule. Allows you to perform actions on HTTP request and response headers, like retrieving, setting, adding to, and removing headers.
You can retrieve a Headers object via the Request.headers and Response.headers properties, and create a new Headers object using the Headers() constructor.
Example