---
title: Response
summary: The Response class as specified by WHATWG
url: https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/globals/interface.Response/
---

**Kind:** Interface  
**Module:** [globals](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/globals/)  
**Package:** @fastly/js-compute 4.0.1  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1548

Extends `Body`.

The Response class as [specified by WHATWG](https://fetch.spec.whatwg.org/#ref-for-dom-response%E2%91%A0)

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

**See also**

- [Response on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Response)

## Constructor

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1664

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

**Parameters**

- `body`: `BodyInit | null` (optional)
- `init`: `ResponseInit` (optional)

## Properties

### headers

**Type:** `Headers`  
**Flags:** read-only  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1554

The response headers.

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

### ok

**Type:** `boolean`  
**Flags:** read-only  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1555

### status

**Type:** `number`  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1560

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

### statusText

**Type:** `string`  
**Flags:** read-only  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1561

### url

**Type:** `string`  
**Flags:** read-only  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1563

### ip

**Type:** `string | undefined`  
**Flags:** read-only  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1570

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

**Type:** `number | undefined`  
**Flags:** read-only  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1577

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

**Type:** `Backend | undefined`  
**Flags:** read-only  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1592

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

### cached

**Type:** `boolean | undefined`  
**Flags:** read-only, since 3.30.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1601

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

**Type:** `boolean | undefined`  
**Flags:** read-only, since 3.30.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1608

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

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

### ttl

**Type:** `number | undefined`  
**Flags:** since 3.30.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1618

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

**Type:** `number | undefined`  
**Flags:** read-only, since 3.30.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1625

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

**Type:** `number | undefined`  
**Flags:** since 3.30.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1632

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

**Type:** `Array<string> | undefined`  
**Flags:** since 3.30.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1639

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

**Type:** `Array<string> | undefined`  
**Flags:** since 3.30.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1646

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

**Type:** `boolean | undefined`  
**Flags:** since 3.30.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1656

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](https://docs.fastly.com/products/pci-compliant-caching-and-delivery)
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

**Flags:** static  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1667

```javascript
static json(data: any, init?: ResponseInit): Response
```

**Parameters**

- `data`: `any`
- `init`: `ResponseInit` (optional)

**Returns**

`Response`

### redirect

**Flags:** static  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1666

```javascript
static redirect(url: string | URL, status?: number): Response
```

**Parameters**

- `url`: `string | URL`
- `status`: `number` (optional)

**Returns**

`Response`

### setManualFramingHeaders

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L1587

```javascript
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`
