Response Object

The response object represents the HTTP response and includes key:value pairs for the status and headers. Response headers can only be modified during the onClientResponse and onOriginResponseevents.

Properties

status

The status code of the HTTP response sent to the client.

// HTTP/1.1 200
response.status;
// => 200

📘

You can set the return value of the response.status field to a 2xx Success, 3xx Redirection, 4xx Client Error, or 5xx Server Error status code.

Methods

The following methods are available for the EdgeWorkers response objects.

MethodsonClient RequestonOrigin RequestonOrigin ResponseonClient Responseresponse Provider
addHeader()
getHeader()
removeHeader()
setHeader()

addHeader()

Adds names and values to a header. If the header already exists, the name and value are appended.

Parameters

addHeader(name, value)

Review the table for information about the available parameters.

ParameterTypeDescription
nameStringName of the header
valueString or ArrayHeader value(s) to add
//
response.addHeader('Powered-By','Akamai EdgeWorkers');
// Powered-By: Akamai EdgeWorkers
// Powered-By: Akamai EdgeWorkers
response.addHeader('Powered-By','Akamai ION');
// Powered-By: Akamai ION 
// Powered-By: Akamai EdgeWorkers

getHeader()

Returns an array of header values by header name. The header names are case insensitive. If the header doesn't exist, a value of undefined is returned.

Parameters

getHeader(name)

Review the table for information about the available parameters.

ParameterTypeDescription
nameArrayNames of the headers in the array
// Content-Length: 100
response.getHeader('Content-Length')[0];
// => "100"

removeHeader()

Removes the named header. The header name is case insensitive.

Parameters

removeHeader(name)

Review the table for information about the available parameters.

ParameterTypeDescription
nameStringName of the header to remove
// Debug: Debug Info
response.removeHeader('Debug');
//

setHeader()

Sets header values and replaces previous ones. Defines the new header name. The value can be a single string or an array.

Parameters

setHeader(name, value)

Review the table for information about the available parameters.

ParameterTypeDescription
nameStringName of the header
valueString or ArrayValue of the new header(s)
// Powered-By: bar
response.setHeader('Powered-By','Akamai EdgeWorkers');
// Powered-By: Akamai EdgeWorkers