pub struct ResponseBuilder { /* private fields */ }
Implementations§
Source§impl ResponseBuilder
impl ResponseBuilder
pub fn new() -> Self
Sourcepub fn with_status(self, status: u16) -> Self
pub fn with_status(self, status: u16) -> Self
Set this response’s status code.
The Workers platform will reject HTTP status codes outside the range of 200..599 inclusive,
and will throw a JavaScript RangeError
, returning a response with an HTTP 500 status code.
Sourcepub fn with_headers(self, headers: Headers) -> Self
pub fn with_headers(self, headers: Headers) -> Self
Set this response’s Headers
.
Sourcepub fn with_header(self, key: &str, value: &str) -> Result<Self>
pub fn with_header(self, key: &str, value: &str) -> Result<Self>
Set a single header on this response.
Sourcepub fn with_cors(self, cors: &Cors) -> Result<Self>
pub fn with_cors(self, cors: &Cors) -> Result<Self>
Sets this response’s cors headers from the Cors
struct.
Example usage:
let cors = Cors::default();
ResponseBuilder::new()
.with_cors(&cors)
.empty()
Sourcepub fn with_websocket(self, websocket: WebSocket) -> Self
pub fn with_websocket(self, websocket: WebSocket) -> Self
Sets this response’s webSocket
option.
This will require a status code 101 to work.
Sourcepub fn with_encode_body(self, encode_body: EncodeBody) -> Self
pub fn with_encode_body(self, encode_body: EncodeBody) -> Self
Set this response’s encodeBody
option.
In most cases this is not needed, but it can be set to “manual” to
return already compressed data to the user without re-compression.
Sourcepub fn with_cf<T: Serialize>(self, cf: T) -> Result<Self>
pub fn with_cf<T: Serialize>(self, cf: T) -> Result<Self>
Set this response’s cf
options. This is used by consumers of the Response
for
informational purposes and has no impact on Workers behavior.
Sourcepub fn stream(self, stream: ReadableStream) -> Response
pub fn stream(self, stream: ReadableStream) -> Response
Build a response with a stream body.
Sourcepub fn body(self, body: ResponseBody) -> Response
pub fn body(self, body: ResponseBody) -> Response
Build a response from a ResponseBody
.
Sourcepub fn from_json<B: Serialize>(self, value: &B) -> Result<Response>
pub fn from_json<B: Serialize>(self, value: &B) -> Result<Response>
Create a Response
using B
as the body encoded as JSON. Sets the associated
Content-Type
header for the Response
as application/json
.
Sourcepub fn from_html(self, html: impl AsRef<str>) -> Result<Response>
pub fn from_html(self, html: impl AsRef<str>) -> Result<Response>
Create a Response
using the body encoded as HTML. Sets the associated Content-Type
header for the Response
as text/html; charset=utf-8
.
Sourcepub fn from_bytes(self, bytes: Vec<u8>) -> Result<Response>
pub fn from_bytes(self, bytes: Vec<u8>) -> Result<Response>
Create a Response
using unprocessed bytes provided. Sets the associated Content-Type
header for the Response
as application/octet-stream
.
Sourcepub fn from_stream<S>(self, stream: S) -> Result<Response>
pub fn from_stream<S>(self, stream: S) -> Result<Response>
Create a Response
using a Stream
for the body. Sets a status
code of 200 and an empty set of Headers. Modify the Response with methods such as
with_status
and with_headers
.
Trait Implementations§
Source§impl Clone for ResponseBuilder
impl Clone for ResponseBuilder
Source§fn clone(&self) -> ResponseBuilder
fn clone(&self) -> ResponseBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more