Struct ResponseBuilder

Source
pub struct ResponseBuilder { /* private fields */ }

Implementations§

Source§

impl ResponseBuilder

Source

pub fn new() -> Self

Source

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.

Source

pub fn with_headers(self, headers: Headers) -> Self

Set this response’s Headers.

Source

pub fn with_header(self, key: &str, value: &str) -> Result<Self>

Set a single header on this response.

Source

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()
Source

pub fn with_websocket(self, websocket: WebSocket) -> Self

Sets this response’s webSocket option. This will require a status code 101 to work.

Source

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.

Source

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.

Source

pub fn fixed(self, body: Vec<u8>) -> Response

Build a response with a fixed-length body.

Source

pub fn stream(self, stream: ReadableStream) -> Response

Build a response with a stream body.

Source

pub fn body(self, body: ResponseBody) -> Response

Build a response from a ResponseBody.

Source

pub fn empty(self) -> Response

Build a response with an empty body.

Source

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.

Source

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.

Source

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.

Source

pub fn from_stream<S>(self, stream: S) -> Result<Response>
where S: TryStream + 'static, S::Ok: Into<Vec<u8>>, S::Error: Into<Error>,

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.

Source

pub fn ok(self, body: impl Into<String>) -> Result<Response>

Create a Response using unprocessed text provided. Sets the associated Content-Type header for the Response as text/plain; charset=utf-8.

Source

pub fn error(self, msg: impl Into<String>, status: u16) -> Result<Response>

A helper method to send an error message to a client. Will return Err if the status code provided is outside the valid HTTP error range of 400-599.

Trait Implementations§

Source§

impl Clone for ResponseBuilder

Source§

fn clone(&self) -> ResponseBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ResponseBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<ResponseBuilder> for ResponseInit

Source§

fn from(init: ResponseBuilder) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,