Headers
ClassHeaders for the Fetch API in RemoteServiceModule.
- Snapchat: not supported
- SPECS: fully supported
- Camera Kit Web: not supported
- Camera Kit Mobile: not supported
- SnapchatNot supported — Available on SPECS only
- SPECSFully supported
- Camera Kit WebNot supported — Available on SPECS only
- Camera Kit MobileNot supported — Available on SPECS only
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.
Index
Example
let myHeaders = new Headers();
myHeaders.append("Content-Type", "text/xml");
myHeaders.get("Content-Type"); // should return 'text/xml'
Extends
Constructors
Constructor
new Headers():
Headers
Returns
Headers
Overrides
ScriptObject.constructor
Methods
append()
append(
name,value):void
SPECS
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'
Parameters
| Parameter | Type |
|---|---|
name | string |
value | string |
Returns
void
delete()
delete(
name):void
SPECS
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
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
void
entries()
entries():
string[][]
SPECS
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
string[][]
get()
get(
name):string
SPECS
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"
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
string
getTypeName()
staticgetTypeName():TypeName<Headers>
SPECS
Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().
Returns
TypeName<Headers>
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
has()
has(
name):boolean
SPECS
Returns a boolean stating whether the Headers object contains the given header.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
boolean
isOfType()
isOfType(
type):boolean
Returns true if the object matches or derives from the passed in type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
isSame()
isSame(
other):boolean
Returns true if this object is the same as other. Useful for checking if two references point to the same thing.
Parameters
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
keys()
keys():
string[]
SPECS
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);
}
Returns
string[]
set()
set(
name,value):void
SPECS
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'
Parameters
| Parameter | Type |
|---|---|
name | string |
value | string |
Returns
void
values()
values():
string[]
SPECS
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);
}
Returns
string[]