Struct worker_plus::Response

source ·
pub struct Response { /* private fields */ }
Expand description

A Response representation for working with or returning a response to a Request.

Implementations§

Create a Response using B as the body encoded as prettified JSON. Sets the associated Content-Type header for the Response as application/json.

Create a Response using B as the body encoded as JSON. Sets the associated Content-Type header for the Response as application/json.

Create a Response using the body encoded as HTML. Sets the associated Content-Type header for the Response as text/html.

Create a Response using unprocessed bytes provided. Sets the associated Content-Type header for the Response as application/octet-stream.

Create a Response using a ResponseBody variant. Sets a status code of 200 and an empty set of Headers. Modify the Response with methods such as with_status and with_headers.

Create a Response using a WebSocket client. Configures the browser to switch protocols (using status code 101) and returns the websocket.

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.

Create a Response using unprocessed text provided. Sets the associated Content-Type header for the Response as text/plain.

Create an empty Response with a 200 status code.

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.

Create a Response which redirects to the specified URL with default status_code of 302

Create a Response which redirects to the specified URL with a custom status_code

Get the HTTP Status code of this Response.

Access this response’s body

Access this response’s body as plaintext.

Access this response’s body encoded as JSON.

Access this response’s body encoded as raw bytes.

Access this response’s body as a Stream of bytes.

Set this response’s Headers.

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.

Sets this response’s cors headers from the Cors struct. Example usage:

use worker::*;
fn fetch() -> worker::Result<Response> {
    let cors = Cors::default();
    Response::empty()?
        .with_cors(&cors)
}

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

Read the Headers on this response.

Get a mutable reference to the Headers on this response.

Clones the response so it can be used multiple times.

Trait Implementations§

Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.