The Response
interface represents an HTTP response and is part of the Fetch API.
let response = new Response(body, init);
body
optional
An object that defines the body text for the response. Can be null
or any one of the following types:
init
optional
options
object that contains custom settings to apply to the response.Valid options for the options
object include:
cf
any | null
encodeBody
string
content-encoding
header when transmitting, to serve data that is already compressed, this property has to be set to "manual"
, otherwise the default is "automatic"
.headers
Headers | ByteString
Headers
object or object literal of ByteString
â key-value pairs.status
int
200
.statusText
string
OK
.webSocket
WebSocket | null
response.webSocket
. This establishes a WebSocket connection proxied through a Worker. Note that you cannot intercept data flowing over a WebSocket connection.response.body
Readable Stream
response.bodyUsed
boolean
response.headers
Headers
response.ok
boolean
200
-299
).response.redirected
boolean
response.status
int
200
to indicate success).response.statusText
string
OK
for 200
).response.url
string
response.webSocket
WebSocket?
response.webSocket
. This establishes a WebSocket connection proxied through a Worker. Note that you cannot intercept data flowing over a WebSocket connection.clone()
: Response
Response
object.json()
: Response
redirect()
: Response
Response
implements the Body
â mixin of the Fetch API â, and therefore Response
instances additionally have the following methods available:
arrayBuffer()
: Promise<ArrayBuffer>
Response
stream, reads it to completion, and returns a promise that resolves with an ArrayBuffer
â.formData()
: Promise<FormData>
Response
stream, reads it to completion, and returns a promise that resolves with a FormData
â object.json()
: Promise<JSON>
text()
: Promise<USVString>
Response
stream, reads it to completion, and returns a promise that resolves with a USVString
â (text).The Content-Length
header will be automatically set by the runtime based on whatever the data source for the Response
is. Any value manually set by user code in the Headers
will be ignored. To have a Content-Length
header with a specific value specified, the body
of the Response
must be either a FixedLengthStream
or a fixed-length value just as a string or TypedArray
.
A FixedLengthStream
is an identity TransformStream
that permits only a fixed number of bytes to be written to it.
const { writable, readable } = new FixedLengthStream(11);
const enc = new TextEncoder();
const writer = writable.getWriter();
writer.write(enc.encode("hello world"));
writer.end();
return new Response(readable);
Using any other type of ReadableStream
as the body of a response will result in chunked encoding being used.
Request
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4