Skip to main content

Headers

Class

Headers 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

Platform details

  • Snapchat — Not supported — Available on SPECS only.

  • SPECS — Fully supported.

  • Camera Kit Web — Not supported — Available on SPECS only.

  • Camera Kit Mobile — Not 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

ParameterType
namestring
valuestring

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

ParameterType
namestring

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

ParameterType
namestring

Returns

string


getTypeName()

static getTypeName(): 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

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


has()

has(name): boolean

SPECS

Returns a boolean stating whether the Headers object contains the given header.

Parameters

ParameterType
namestring

Returns

boolean


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


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

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame


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

ParameterType
namestring
valuestring

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[]