Headers(headers, format)

This class provides a representation of HTTP request or response headers, that operates in the same way in multiple contexts (i.e. within the SSR Server as well as the request-processor).

Within a Headers instance, headers are referenced using lower-case names. Use getHeader to access the value for a header. If there are multiple values, this will return the first value. This class internally supports round-trip preservation of multi-value headers, but does not yet provide a way to access them.

Constructor

new Headers(headers, format)

Construct a Headers object from either an AWS Lambda Event headers object, or an http.IncomingMessage headers object.

Project code should never need to call this constructor.

Parameters:
Name Type Description
headers Object

the input headers

format String

either 'http' or 'aws'

Members

modified

Return true if and only if any set or delete methods were called on this instance after construction. This does not actually test if the headers values have been changed, just whether any mutating methods have been called.

Methods

deleteHeader(key)

Remove any header with the given key

Parameters:
Name Type Description
key

getHeader(key)

Return the FIRST value of the header with the given key. This is for single-value headers only: Location, Access-Control-*, etc If the header is not present, returns undefined.

Parameters:
Name Type Description
key String

header name

getSetCookie()

Get the value of the set-cookie header(s), returning an array of strings. Always returns an array, even if it's empty.

keys()

Return an array of the header keys (all lower-case)

setHeader(key, value)

Set the value of the header with the given key. This is for single- value headers only (see getHeader). Setting the value removes ALL other values for the given key.

Parameters:
Name Type Description
key String

header name

value String

header value

setSetCookie(values)

Set the value of the set-cookie header(s)

Parameters:
Name Type Description
values Array.<String>

toAWSFormat()

Return the headers in AWS (Lambda event) format.

Project code should never need to use this method.

toHTTPFormat()

Return the headers in Express (http.IncomingMessage) format.

RFC2616 allows some flexibility in how multiple values are combined into a single header value. We separate with ', ' rather than just ',' to maintain previous behaviour.

Project code should never need to use this method.

toObject()

Return the headers in the same format (aws or http) that was used to construct them.

Project code should never need to use this method.