pub struct HttpResponse {
pub status: StatusCode,
pub body: ResponseBody,
pub content_type: &'static str,
pub headers: Vec<(String, String)>,
}Fields§
§status: StatusCode§body: ResponseBody§content_type: &'static str§headers: Vec<(String, String)>Extra response headers applied by the HTTP adapter.
Owned name/value pairs so callers can set dynamic values
(e.g. Content-Disposition with a generated filename). This is a
simple list, not a full HeaderMap with multi-value / typed APIs.
Implementations§
Source§impl HttpResponse
impl HttpResponse
pub fn new( status: StatusCode, body: Vec<u8>, content_type: &'static str, ) -> Self
Sourcepub fn json(status: StatusCode, body: impl Serialize) -> Self
pub fn json(status: StatusCode, body: impl Serialize) -> Self
Serializes body as JSON. This is the single place JSON encoding
happens — everything else below routes through here.
pub fn text(status: StatusCode, body: impl Into<String>) -> Self
pub fn bytes(status: StatusCode, body: impl Into<Vec<u8>>) -> Self
Sourcepub fn body_bytes(&self) -> Option<&[u8]>
pub fn body_bytes(&self) -> Option<&[u8]>
Buffered body bytes, if this response is not streaming.
Trait Implementations§
Source§impl IntoCaelixResponse for HttpResponse
impl IntoCaelixResponse for HttpResponse
fn into_response(self) -> HttpResponse
Auto Trait Implementations§
impl !RefUnwindSafe for HttpResponse
impl !Sync for HttpResponse
impl !UnwindSafe for HttpResponse
impl Freeze for HttpResponse
impl Send for HttpResponse
impl Unpin for HttpResponse
impl UnsafeUnpin for HttpResponse
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> 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