Response

Interfacein globals@fastly/js-compute 4.0.0View source

Extends Body.

The Response class as specified by WHATWG

Note: Can only be used when processing requests, not during build-time initialization.

See also

Constructor

new Response(body?: BodyInit | null, init?: ResponseInit)

Parameters

body: BodyInit | nulloptional
init: ResponseInitoptional

Properties

headers

Headersread-onlyView source

The response headers.

May be modified even for upstream responses prior to storage in the cache.

ok

booleanread-onlyView source

status

numberView source

The response status. May be modified prior to storage in the cache.

statusText

stringread-onlyView source

url

stringread-onlyView source

ip

string | undefinedread-onlyView source

Fastly-specific property - obtain the IP address used for the request

Undefined for user-created responses and when the response is returned from the cache. Set cacheOverride: new CacheOverride("pass") to ensure a value.

port

number | undefinedread-onlyView source

Fastly-specific property - Obtain the port used for the request

Undefined for user-created responses and when the response is returned from the cache. Set cacheOverride: new CacheOverride("pass") to ensure a value.

backend

Backend | undefinedread-onlyView source

The backend this response was received from, or undefined for user-created responses.

cached

boolean | undefinedread-onlysince 3.30.0View source

Fastly-specific property - Returns whether the Response resulted from a cache hit. For request collapsing, typically one response will show as a miss, and the others (that awaited that response) will show as hits.

Undefined if the environment does not support the new HTTP Cache hostcalls.

stale

boolean | undefinedread-onlysince 3.30.0View source

Fastly-specific property - Returns whether the cached Response is considered stale.

Undefined if the environment does not support the new HTTP Cache hostcalls.

ttl

number | undefinedsince 3.30.0View source

Fastly-specific property - Get the Time to Live (TTL) in the cache for this response in seconds, if it is cached.

The TTL determines the duration of "freshness" for the cached response after it is inserted into the cache.

Undefined if the response is not cached or the environment does not support the HTTP Cache hostcalls. May be modified prior to injection into the cache.

age

number | undefinedread-onlysince 3.30.0View source

Fastly-specific property - The current age of the response in seconds, if it is cached.

Undefined if the response is not cached or the environment does not support the HTTP Cache hostcalls. May be modified prior to injection into the cache.

swr

number | undefinedsince 3.30.0View source

Fastly-specific property - The time in seconds for which the response can safely be used despite being considered stale, if it is cached.

Undefined if the response is not cached or the environment does not support the HTTP Cache hostcalls. May be modified prior to injection into the cache.

vary

Array<string> | undefinedsince 3.30.0View source

Fastly-specific property - The set of request headers for which the response may vary.

Undefined if the response is not cached or the environment does not support the HTTP Cache hostcalls. May be modified prior to injection into the cache.

surrogateKeys

Array<string> | undefinedsince 3.30.0View source

Fastly-specific property - The surrogate keys for the cached response.

Undefined if the response is not cached or the environment does not support the HTTP Cache hostcalls. May be modified prior to injection into the cache.

pci

boolean | undefinedsince 3.30.0View source

Fastly-specific property - Get or set whether this response should only be stored via PCI/HIPAA-compliant non-volatile caching.

See the Fastly PCI-Compliant Caching and Delivery documentation for details.

Undefined if the response is not cached or the environment does not support the HTTP Cache hostcalls. May be modified prior to injection into the cache.

Methods

json

staticView source
static json(data: any, init?: ResponseInit): Response

Parameters

data: any
init: ResponseInitoptional

Returns

redirect

staticView source
static redirect(url: string | URL, status?: number): Response

Parameters

url: string | URL
status: numberoptional

Returns

setManualFramingHeaders

View source
setManualFramingHeaders(manual: boolean): void

Controls how framing headers (Content-Length, Transfer-Encoding) are determined. In "manual" mode, any provided framing headers will be honored. In "automatic" mode (the default), they are set based on the body.

Parameters

manual: boolean

Whether to use manual mode for framing headers.

Returns

void