pub struct Response { /* private fields */ }
Expand description
Represents an HTTP response.
Implementations§
Source§impl Response
impl Response
Sourcepub fn new(body: Vec<u8>) -> Self
pub fn new(body: Vec<u8>) -> Self
Creates a new response with the given body.
use snx::response::Response;
let res = Response::new("hello world!".as_bytes().to_vec());
Sourcepub fn status(&self) -> &StatusCode
pub fn status(&self) -> &StatusCode
Gets a reference to the HTTP status code.
use snx::{response::Response, StatusCode};
let res = Response::new("hello world!".as_bytes().to_vec());
let status = res.status();
Sourcepub fn status_mut(&mut self) -> &mut StatusCode
pub fn status_mut(&mut self) -> &mut StatusCode
Gets a mutable reference to the HTTP status code.
use snx::{response::Response, StatusCode};
let mut res = Response::new("hello world!".as_bytes().to_vec());
*res.status_mut() = StatusCode::NotFound;
Sourcepub fn headers(&self) -> &HeaderMap
pub fn headers(&self) -> &HeaderMap
Gets a reference to the HTTP headers.
use snx::response::Response;
let res = Response::new("hello world!".as_bytes().to_vec());
let headers = res.headers();
Sourcepub fn headers_mut(&mut self) -> &mut HeaderMap
pub fn headers_mut(&mut self) -> &mut HeaderMap
Gets a mutable reference to the HTTP headers.
use snx::response::Response;
let mut res = Response::new("hello world!".as_bytes().to_vec());
*res.headers_mut() = ("Content-Type", "application/json").into();
Sourcepub fn body(&self) -> &Option<Vec<u8>>
pub fn body(&self) -> &Option<Vec<u8>>
Gets a reference to the body.
use snx::{response::Response, StatusCode};
let res = Response::new("hello world!".as_bytes().to_vec());
let body = res.body();
Sourcepub fn serialize_to_raw_http_response(self) -> Vec<u8> ⓘ
pub fn serialize_to_raw_http_response(self) -> Vec<u8> ⓘ
Serializes the response object to a raw HTTP response.
use snx::response::Response;
let bytes = Response::default().serialize_to_raw_http_response();
Trait Implementations§
Source§impl IntoResponse for Response
impl IntoResponse for Response
fn into_response(self) -> Response
Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnwindSafe for Response
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more