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 moresource§impl Debug for ResponseBuilder
impl Debug for ResponseBuilder
source§impl From<ResponseBuilder> for ResponseInit
impl From<ResponseBuilder> for ResponseInit
source§fn from(init: ResponseBuilder) -> Self
fn from(init: ResponseBuilder) -> Self
Auto Trait Implementations§
impl Freeze for ResponseBuilder
impl RefUnwindSafe for ResponseBuilder
impl !Send for ResponseBuilder
impl !Sync for ResponseBuilder
impl Unpin for ResponseBuilder
impl UnwindSafe for ResponseBuilder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)