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 onOriginResponse events.

Limit body string length to 2000 characters to prevent a 500 error response. If called multiple times, the event handler will use the most recent response.

Properties for the Response Object

status

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

// HTTP/1.1 200
response.status;
// => 200
Note: 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 for the Response Object

The following methods are available for the EdgeWorkers response objects.

addHeader(name, value)

Adds names and values to a header. If the header already exists, the name and value are appended. The value can be a single string or an array.

Review the table for information about the possible arguments.

Argument Description Object Type
name Names of the header String
value Value of the header String
//
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(name)

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

Review the table for information about the possible arguments.

Argument Description Object Type
name Names of the headers in the array Array
// Content-Length: 100
response.getHeader('Content-Length')[0];
// => "100"

removeHeader(name)

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

Review the table for information about the possible arguments.

Argument Description Object Type
name Names of the header to remove String
// Debug: Debug Info
response.removeHeader('Debug');
//

setHeader(name, value)

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

Review the table for information about the possible arguments.

Argument Description Object Type
name Name of the header String
value Value of the header String or Array
// Powered-By: bar
response.setHeader('Powered-By','Akamai EdgeWorkers');
// Powered-By: Akamai EdgeWorkers