HttpResponse

Struct HttpResponse 

Source
pub struct HttpResponse<'a> {
    pub status_code: StatusCode,
    pub headers: Vec<HttpHeader<'a>, 16>,
    pub body: ResponseBody<'a>,
}
Expand description

HTTP Response struct with status code, headers and body

This struct represents the response received from an HTTP server. It contains the status code, headers, and the response body which can be either text or binary data using zero-copy references.

Fieldsยง

ยงstatus_code: StatusCode

The HTTP status code (e.g., 200 for OK, 404 for Not Found)

ยงheaders: Vec<HttpHeader<'a>, 16>

A collection of response headers with both names and values

ยงbody: ResponseBody<'a>

The response body that can handle both text and binary data

Implementationsยง

Sourceยง

impl HttpResponse<'_>

Source

pub fn get_header(&self, name: &str) -> Option<&str>

Get a header value by name (case-insensitive)

Source

pub fn content_type(&self) -> Option<&str>

Get the Content-Type header value

Source

pub fn content_length(&self) -> Option<usize>

Get the Content-Length header value as a number

Source

pub fn is_success(&self) -> bool

Check if the response indicates success (2xx status codes)

Source

pub fn is_client_error(&self) -> bool

Check if the response is a client error (4xx status codes)

Source

pub fn is_server_error(&self) -> bool

Check if the response is a server error (5xx status codes)

Source

pub fn build_bytes<const MAX_RESPONSE_SIZE: usize>( &self, ) -> Vec<u8, MAX_RESPONSE_SIZE>

Build HTTP response bytes from this HttpResponse

Auto Trait Implementationsยง

ยง

impl<'a> Freeze for HttpResponse<'a>

ยง

impl<'a> RefUnwindSafe for HttpResponse<'a>

ยง

impl<'a> Send for HttpResponse<'a>

ยง

impl<'a> Sync for HttpResponse<'a>

ยง

impl<'a> Unpin for HttpResponse<'a>

ยง

impl<'a> UnwindSafe for HttpResponse<'a>

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