pub struct Response {
pub status: StatusCode,
pub headers: HeaderMap,
pub body: Bytes,
}Expand description
A formatted HTTP response.
Fields§
§status: StatusCodeHTTP status code
headers: HeaderMapResponse headers
body: BytesResponse body
Implementations§
Source§impl Response
impl Response
Sourcepub fn new(status: StatusCode, body: impl Into<Bytes>) -> Self
pub fn new(status: StatusCode, body: impl Into<Bytes>) -> Self
Create a new response.
Sourcepub fn json<T: Serialize>(status: StatusCode, value: &T) -> Result<Self, Error>
pub fn json<T: Serialize>(status: StatusCode, value: &T) -> Result<Self, Error>
Create a JSON response.
Sourcepub fn empty(status: StatusCode) -> Self
pub fn empty(status: StatusCode) -> Self
Create an empty response.
Sourcepub fn set_header(&mut self, name: &str, value: &str)
pub fn set_header(&mut self, name: &str, value: &str)
Set a header.
Sourcepub fn set_content_type(&mut self, content_type: &str)
pub fn set_content_type(&mut self, content_type: &str)
Set Content-Type header.
Sourcepub fn set_content_range(&mut self, range: &ContentRange)
pub fn set_content_range(&mut self, range: &ContentRange)
Set Content-Range header.
Sourcepub fn set_location(&mut self, location: &str)
pub fn set_location(&mut self, location: &str)
Set Location header.
Trait Implementations§
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