pub struct Response<B> { /* private fields */ }
Expand description
An HTTP response.
Implementations§
source§impl Response<BoxBody>
impl Response<BoxBody>
sourcepub fn new(status: StatusCode) -> Response<BoxBody>
pub fn new(status: StatusCode) -> Response<BoxBody>
Constructs a new response with default body.
sourcepub fn build(status: StatusCode) -> ResponseBuilder
pub fn build(status: StatusCode) -> ResponseBuilder
Constructs a new response builder.
sourcepub fn bad_request() -> Response<BoxBody>
pub fn bad_request() -> Response<BoxBody>
Constructs a new response with status 400 Bad Request.
sourcepub fn internal_server_error() -> Response<BoxBody>
pub fn internal_server_error() -> Response<BoxBody>
Constructs a new response with status 500 Internal Server Error.
source§impl<B> Response<B>
impl<B> Response<B>
sourcepub fn with_body(status: StatusCode, body: B) -> Response<B>
pub fn with_body(status: StatusCode, body: B) -> Response<B>
Constructs a new response with given body.
sourcepub fn head(&self) -> &ResponseHead
pub fn head(&self) -> &ResponseHead
Returns a reference to the head of this response.
sourcepub fn head_mut(&mut self) -> &mut ResponseHead
pub fn head_mut(&mut self) -> &mut ResponseHead
Returns a mutable reference to the head of this response.
sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Returns the status code of this response.
sourcepub fn status_mut(&mut self) -> &mut StatusCode
pub fn status_mut(&mut self) -> &mut StatusCode
Returns a mutable reference the status code of this response.
sourcepub fn headers_mut(&mut self) -> &mut HeaderMap
pub fn headers_mut(&mut self) -> &mut HeaderMap
Returns a mutable reference to response headers.
sourcepub fn keep_alive(&self) -> bool
pub fn keep_alive(&self) -> bool
Returns true if keep-alive is enabled.
sourcepub fn extensions(&self) -> Ref<'_, Extensions>
pub fn extensions(&self) -> Ref<'_, Extensions>
Returns a reference to the request-local data/extensions container.
sourcepub fn extensions_mut(&mut self) -> RefMut<'_, Extensions>
pub fn extensions_mut(&mut self) -> RefMut<'_, Extensions>
Returns a mutable reference to the request-local data/extensions container.
sourcepub fn into_parts(self) -> (Response<()>, B)
pub fn into_parts(self) -> (Response<()>, B)
Returns split head and body.
§Implementation Notes
Due to internal performance optimizations, the first element of the returned tuple is a
Response
as well but only contains the head of the response this was called on.
sourcepub fn map_body<F, B2>(self, f: F) -> Response<B2>where
F: FnOnce(&mut ResponseHead, B) -> B2,
pub fn map_body<F, B2>(self, f: F) -> Response<B2>where
F: FnOnce(&mut ResponseHead, B) -> B2,
Map the current body type to another using a closure, returning a new response.
Closure receives the response head and the current body type.
sourcepub fn map_into_boxed_body(self) -> Response<BoxBody>where
B: MessageBody + 'static,
pub fn map_into_boxed_body(self) -> Response<BoxBody>where
B: MessageBody + 'static,
Map the current body to a type-erased BoxBody
.
Trait Implementations§
source§impl<B> Debug for Response<B>where
B: MessageBody,
impl<B> Debug for Response<B>where
B: MessageBody,
source§impl<B> From<HttpResponse<B>> for Response<B>
impl<B> From<HttpResponse<B>> for Response<B>
source§fn from(res: HttpResponse<B>) -> Self
fn from(res: HttpResponse<B>) -> Self
source§impl From<HttpResponseBuilder> for Response<BoxBody>
impl From<HttpResponseBuilder> for Response<BoxBody>
source§fn from(builder: HttpResponseBuilder) -> Self
fn from(builder: HttpResponseBuilder) -> Self
source§impl<B> From<Response<B>> for HttpResponse<B>
impl<B> From<Response<B>> for HttpResponse<B>
source§impl From<ResponseBuilder> for Response<EitherBody<()>>
impl From<ResponseBuilder> for Response<EitherBody<()>>
source§fn from(builder: ResponseBuilder) -> Response<EitherBody<()>>
fn from(builder: ResponseBuilder) -> Response<EitherBody<()>>
source§impl<B> From<ServiceResponse<B>> for Response<B>
impl<B> From<ServiceResponse<B>> for Response<B>
source§fn from(res: ServiceResponse<B>) -> Response<B>
fn from(res: ServiceResponse<B>) -> Response<B>
source§impl Responder for Response<BoxBody>
impl Responder for Response<BoxBody>
type Body = BoxBody
source§fn respond_to(self, _: &HttpRequest) -> HttpResponse<Self::Body>
fn respond_to(self, _: &HttpRequest) -> HttpResponse<Self::Body>
HttpResponse
.