logo
pub struct Response {
    pub status_code: u16,
    pub headers: Headers,
    pub body: Option<Box<dyn BodyWrite>>,
}
Expand description

Response type. It is just one container with a couple of parameters (headers, body, status code etc).

Fields

status_code: u16

The HTTP Status code number

headers: Headersbody: Option<Box<dyn BodyWrite>>

Implementations

Create a Response. By default, the status code is 200 and content type is “text/html; charset=UTF-8”. Remember to set content length if necessary. Mostly you should just get a response that is converted from other types, which set the content length automatically. For example:

// Content length is set automatically
let response = Response::from("Hello");

Create an empty response without body.

Get status name.

Returns the response content type if available.

Set response content type. If the mimetype passed is a mimetype starting with text/ or something that needs a charset, the charset(UTF-8) parameter is appended to it.

Returns the response content length if available.

Set content length.

Sets cookie.

Trait Implementations

Formats the value using the given formatter. Read more

Convert to response body. The content length is set automatically.

Convert to response body. The content length is set automatically.

Convert to response body. The content length is set automatically if file size is available from metadata.

Convert a new string to response body. The content length is set automatically.

Convert to response body. The content length is set automatically.

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.

Get the TypeId of this object.