Struct snowboard::Response

source ยท
pub struct Response {
    pub version: HttpVersion,
    pub status: u16,
    pub status_text: &'static str,
    pub bytes: Vec<u8>,
    pub headers: Option<Headers>,
}
Expand description

Response struct. Contains the response data and converts it to text if needed.

Fieldsยง

ยงversion: HttpVersion

HTTP protocol version.

ยงstatus: u16

HTTP status code.

ยงstatus_text: &'static str

According text for the status.

ยงbytes: Vec<u8>

The request body, stored in bytes.

ยงheaders: Option<Headers>

Headers of the response

Implementationsยง

sourceยง

impl Response

source

pub fn new( version: HttpVersion, status: u16, status_text: &'static str, bytes: Vec<u8>, headers: Option<Headers> ) -> Self

Manually create a Response instance. Use Response::ok(), Response::bad_request() etc. instead when possible.

source

pub fn send_to<T: Write>(&mut self, stream: &mut T) -> Result<(), Error>

Writes the response, consuming its body.

source

pub fn with_header(self, key: &'static str, value: String) -> Self

Sets a header to the response, returning the response itself. Use Response::with_content_type for the โ€˜Content-Typeโ€™ header.

source

pub fn with_content_type(self, value: String) -> Self

Sets the content type of the response, returning the response itself. Note that this does not check if the content type is valid, so be careful.

source

pub fn set_header(&mut self, key: &'static str, value: String) -> &mut Self

Sets the content length of a reference to a response

source

pub fn set_content_length(&mut self, len: usize) -> &mut Self

Sets the content length of a reference to a response

source

pub fn to_bytes(&mut self) -> Vec<u8>

Converts the Response into a HTTP Response, as bytes.

source

pub fn len(&self) -> usize

Gets the length of the response body.

source

pub fn is_empty(&self) -> bool

Checks if the response body is empty.

source

pub fn with_default_headers(self) -> Self

Adds optional but useful headers to a response. This includes the Content-Length header, Date header and Server header.

Trait Implementationsยง

sourceยง

impl Clone for Response

sourceยง

fn clone(&self) -> Response

Returns a copy 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 Response

sourceยง

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

Formats the value using the given formatter. Read more
sourceยง

impl Default for Response

sourceยง

fn default() -> Self

Returns the โ€œdefault valueโ€ for a type. Read more
sourceยง

impl Display for Response

sourceยง

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

Formats the value using the given formatter. Read more
sourceยง

impl From<Response> for Vec<u8>

sourceยง

fn from(res: Response) -> Self

Converts to this type from the input type.
sourceยง

impl PartialEq for Response

sourceยง

fn eq(&self, other: &Response) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 ยท sourceยง

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
sourceยง

impl ResponseLike for Response

sourceยง

fn to_response(self) -> Response

Converts self into a Response.
sourceยง

impl Eq for Response

sourceยง

impl StructuralEq for Response

sourceยง

impl StructuralPartialEq for Response

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> From<T> for T

sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

ยง

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> ToString for T
where T: Display + ?Sized,

sourceยง

default fn to_string(&self) -> String

Converts the given value to a String. Read more
sourceยง

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

ยง

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>,

ยง

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.