pub struct HttpResponse<B = BoxBody> { /* private fields */ }Expand description
An outgoing response.
Implementations§
Source§impl HttpResponse
impl HttpResponse
Sourcepub fn Continue() -> HttpResponseBuilder ⓘ
pub fn Continue() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::CONTINUE.
Sourcepub fn SwitchingProtocols() -> HttpResponseBuilder ⓘ
pub fn SwitchingProtocols() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::SWITCHING_PROTOCOLS.
Sourcepub fn Processing() -> HttpResponseBuilder ⓘ
pub fn Processing() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::PROCESSING.
Sourcepub fn Ok() -> HttpResponseBuilder ⓘ
pub fn Ok() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::OK.
Sourcepub fn Created() -> HttpResponseBuilder ⓘ
pub fn Created() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::CREATED.
Sourcepub fn Accepted() -> HttpResponseBuilder ⓘ
pub fn Accepted() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::ACCEPTED.
Sourcepub fn NonAuthoritativeInformation() -> HttpResponseBuilder ⓘ
pub fn NonAuthoritativeInformation() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::NON_AUTHORITATIVE_INFORMATION.
Sourcepub fn NoContent() -> HttpResponseBuilder ⓘ
pub fn NoContent() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::NO_CONTENT.
Sourcepub fn ResetContent() -> HttpResponseBuilder ⓘ
pub fn ResetContent() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::RESET_CONTENT.
Sourcepub fn PartialContent() -> HttpResponseBuilder ⓘ
pub fn PartialContent() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::PARTIAL_CONTENT.
Sourcepub fn MultiStatus() -> HttpResponseBuilder ⓘ
pub fn MultiStatus() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::MULTI_STATUS.
Sourcepub fn AlreadyReported() -> HttpResponseBuilder ⓘ
pub fn AlreadyReported() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::ALREADY_REPORTED.
Sourcepub fn ImUsed() -> HttpResponseBuilder ⓘ
pub fn ImUsed() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::IM_USED.
Sourcepub fn MultipleChoices() -> HttpResponseBuilder ⓘ
pub fn MultipleChoices() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::MULTIPLE_CHOICES.
Sourcepub fn MovedPermanently() -> HttpResponseBuilder ⓘ
pub fn MovedPermanently() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::MOVED_PERMANENTLY.
Sourcepub fn Found() -> HttpResponseBuilder ⓘ
pub fn Found() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::FOUND.
Sourcepub fn SeeOther() -> HttpResponseBuilder ⓘ
pub fn SeeOther() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::SEE_OTHER.
Sourcepub fn NotModified() -> HttpResponseBuilder ⓘ
pub fn NotModified() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::NOT_MODIFIED.
Sourcepub fn UseProxy() -> HttpResponseBuilder ⓘ
pub fn UseProxy() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::USE_PROXY.
Sourcepub fn TemporaryRedirect() -> HttpResponseBuilder ⓘ
pub fn TemporaryRedirect() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::TEMPORARY_REDIRECT.
Sourcepub fn PermanentRedirect() -> HttpResponseBuilder ⓘ
pub fn PermanentRedirect() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::PERMANENT_REDIRECT.
Sourcepub fn BadRequest() -> HttpResponseBuilder ⓘ
pub fn BadRequest() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::BAD_REQUEST.
Creates a new response builder with the status code StatusCode::UNAUTHORIZED.
Sourcepub fn PaymentRequired() -> HttpResponseBuilder ⓘ
pub fn PaymentRequired() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::PAYMENT_REQUIRED.
Sourcepub fn Forbidden() -> HttpResponseBuilder ⓘ
pub fn Forbidden() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::FORBIDDEN.
Sourcepub fn NotFound() -> HttpResponseBuilder ⓘ
pub fn NotFound() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::NOT_FOUND.
Sourcepub fn MethodNotAllowed() -> HttpResponseBuilder ⓘ
pub fn MethodNotAllowed() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::METHOD_NOT_ALLOWED.
Sourcepub fn NotAcceptable() -> HttpResponseBuilder ⓘ
pub fn NotAcceptable() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::NOT_ACCEPTABLE.
Sourcepub fn ProxyAuthenticationRequired() -> HttpResponseBuilder ⓘ
pub fn ProxyAuthenticationRequired() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::PROXY_AUTHENTICATION_REQUIRED.
Sourcepub fn RequestTimeout() -> HttpResponseBuilder ⓘ
pub fn RequestTimeout() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::REQUEST_TIMEOUT.
Sourcepub fn Conflict() -> HttpResponseBuilder ⓘ
pub fn Conflict() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::CONFLICT.
Sourcepub fn Gone() -> HttpResponseBuilder ⓘ
pub fn Gone() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::GONE.
Sourcepub fn LengthRequired() -> HttpResponseBuilder ⓘ
pub fn LengthRequired() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::LENGTH_REQUIRED.
Sourcepub fn PreconditionFailed() -> HttpResponseBuilder ⓘ
pub fn PreconditionFailed() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::PRECONDITION_FAILED.
Sourcepub fn PayloadTooLarge() -> HttpResponseBuilder ⓘ
pub fn PayloadTooLarge() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::PAYLOAD_TOO_LARGE.
Sourcepub fn UriTooLong() -> HttpResponseBuilder ⓘ
pub fn UriTooLong() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::URI_TOO_LONG.
Sourcepub fn UnsupportedMediaType() -> HttpResponseBuilder ⓘ
pub fn UnsupportedMediaType() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::UNSUPPORTED_MEDIA_TYPE.
Sourcepub fn RangeNotSatisfiable() -> HttpResponseBuilder ⓘ
pub fn RangeNotSatisfiable() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::RANGE_NOT_SATISFIABLE.
Sourcepub fn ExpectationFailed() -> HttpResponseBuilder ⓘ
pub fn ExpectationFailed() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::EXPECTATION_FAILED.
Sourcepub fn ImATeapot() -> HttpResponseBuilder ⓘ
pub fn ImATeapot() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::IM_A_TEAPOT.
Sourcepub fn MisdirectedRequest() -> HttpResponseBuilder ⓘ
pub fn MisdirectedRequest() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::MISDIRECTED_REQUEST.
Sourcepub fn UnprocessableEntity() -> HttpResponseBuilder ⓘ
pub fn UnprocessableEntity() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::UNPROCESSABLE_ENTITY.
Sourcepub fn Locked() -> HttpResponseBuilder ⓘ
pub fn Locked() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::LOCKED.
Sourcepub fn FailedDependency() -> HttpResponseBuilder ⓘ
pub fn FailedDependency() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::FAILED_DEPENDENCY.
Sourcepub fn UpgradeRequired() -> HttpResponseBuilder ⓘ
pub fn UpgradeRequired() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::UPGRADE_REQUIRED.
Sourcepub fn PreconditionRequired() -> HttpResponseBuilder ⓘ
pub fn PreconditionRequired() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::PRECONDITION_REQUIRED.
Sourcepub fn TooManyRequests() -> HttpResponseBuilder ⓘ
pub fn TooManyRequests() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::TOO_MANY_REQUESTS.
Sourcepub fn RequestHeaderFieldsTooLarge() -> HttpResponseBuilder ⓘ
pub fn RequestHeaderFieldsTooLarge() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::REQUEST_HEADER_FIELDS_TOO_LARGE.
Creates a new response builder with the status code StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS.
Sourcepub fn InternalServerError() -> HttpResponseBuilder ⓘ
pub fn InternalServerError() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::INTERNAL_SERVER_ERROR.
Sourcepub fn NotImplemented() -> HttpResponseBuilder ⓘ
pub fn NotImplemented() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::NOT_IMPLEMENTED.
Sourcepub fn BadGateway() -> HttpResponseBuilder ⓘ
pub fn BadGateway() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::BAD_GATEWAY.
Creates a new response builder with the status code StatusCode::SERVICE_UNAVAILABLE.
Sourcepub fn GatewayTimeout() -> HttpResponseBuilder ⓘ
pub fn GatewayTimeout() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::GATEWAY_TIMEOUT.
Sourcepub fn VersionNotSupported() -> HttpResponseBuilder ⓘ
pub fn VersionNotSupported() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::HTTP_VERSION_NOT_SUPPORTED.
Sourcepub fn VariantAlsoNegotiates() -> HttpResponseBuilder ⓘ
pub fn VariantAlsoNegotiates() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::VARIANT_ALSO_NEGOTIATES.
Sourcepub fn InsufficientStorage() -> HttpResponseBuilder ⓘ
pub fn InsufficientStorage() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::INSUFFICIENT_STORAGE.
Sourcepub fn LoopDetected() -> HttpResponseBuilder ⓘ
pub fn LoopDetected() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::LOOP_DETECTED.
Sourcepub fn NotExtended() -> HttpResponseBuilder ⓘ
pub fn NotExtended() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::NOT_EXTENDED.
Sourcepub fn NetworkAuthenticationRequired() -> HttpResponseBuilder ⓘ
pub fn NetworkAuthenticationRequired() -> HttpResponseBuilder ⓘ
Creates a new response builder with the status code StatusCode::NETWORK_AUTHENTICATION_REQUIRED.
Source§impl HttpResponse<BoxBody>
impl HttpResponse<BoxBody>
Sourcepub fn new(status: StatusCode) -> Self
pub fn new(status: StatusCode) -> Self
Constructs a response.
Sourcepub fn build(status: StatusCode) -> HttpResponseBuilder ⓘ
pub fn build(status: StatusCode) -> HttpResponseBuilder ⓘ
Constructs a response builder with specific HTTP status.
Sourcepub fn from_error(error: impl Into<Error>) -> Self
pub fn from_error(error: impl Into<Error>) -> Self
Create an error response.
Source§impl<B> HttpResponse<B>
impl<B> HttpResponse<B>
Sourcepub fn with_body(status: StatusCode, body: B) -> Self
pub fn with_body(status: StatusCode, body: B) -> Self
Constructs a response with body
Sourcepub fn head(&self) -> &ResponseHead
pub fn head(&self) -> &ResponseHead
Returns a reference to response head.
Sourcepub fn head_mut(&mut self) -> &mut ResponseHead
pub fn head_mut(&mut self) -> &mut ResponseHead
Returns a mutable reference to response head.
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Get the response status code
Sourcepub fn status_mut(&mut self) -> &mut StatusCode
pub fn status_mut(&mut self) -> &mut StatusCode
Set the StatusCode for this response
Sourcepub fn headers_mut(&mut self) -> &mut HeaderMap
pub fn headers_mut(&mut self) -> &mut HeaderMap
Get a mutable reference to the headers
Available on crate feature cookies only.
cookies only.Get an iterator for the cookies set by this response.
Available on crate feature cookies only.
cookies only.Add a cookie to this response.
§Errors
Returns an error if the cookie results in a malformed Set-Cookie header.
Available on crate feature cookies only.
cookies only.Add a “removal” cookie to the response that matches attributes of given cookie.
This will cause browsers/clients to remove stored cookies with this name.
The Set-Cookie header added to the response will have:
- name matching given cookie;
- domain matching given cookie;
- path matching given cookie;
- an empty value;
- a max-age of
0; - an expiration date far in the past.
If the cookie you’re trying to remove has an explicit path or domain set, those attributes will need to be included in the cookie passed in here.
§Errors
Returns an error if the given name results in a malformed Set-Cookie header.
Available on crate feature cookies only.
cookies only.Remove all cookies with the given name from this response.
Returns the number of cookies removed.
This method can not cause a browser/client to delete any of its stored cookies. Its only
purpose is to delete cookies that were added to this response using add_cookie
and add_removal_cookie. Use add_removal_cookie to send a “removal” cookie.
Sourcepub fn keep_alive(&self) -> bool
pub fn keep_alive(&self) -> bool
Keep-alive status for this connection
Sourcepub fn extensions(&self) -> Ref<'_, Extensions>
pub fn extensions(&self) -> Ref<'_, Extensions>
Returns reference to the response-local data/extensions container.
Sourcepub fn extensions_mut(&mut self) -> RefMut<'_, Extensions>
pub fn extensions_mut(&mut self) -> RefMut<'_, Extensions>
Returns reference to the response-local data/extensions container.
Sourcepub fn set_body<B2>(self, body: B2) -> HttpResponse<B2>
pub fn set_body<B2>(self, body: B2) -> HttpResponse<B2>
Sets new body.
Sourcepub fn into_parts(self) -> (HttpResponse<()>, B)
pub fn into_parts(self) -> (HttpResponse<()>, B)
Returns split head and body.
§Implementation Notes
Due to internal performance optimizations, the first element of the returned tuple is an
HttpResponse as well but only contains the head of the response this was called on.
Sourcepub fn drop_body(self) -> HttpResponse<()>
pub fn drop_body(self) -> HttpResponse<()>
Drops body and returns new response.
Sourcepub fn map_body<F, B2>(self, f: F) -> HttpResponse<B2>where
F: FnOnce(&mut ResponseHead, B) -> B2,
pub fn map_body<F, B2>(self, f: F) -> HttpResponse<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_left_body<R>(self) -> HttpResponse<EitherBody<B, R>>
pub fn map_into_left_body<R>(self) -> HttpResponse<EitherBody<B, R>>
Map the current body type B to EitherBody::Left(B).
Useful for middleware which can generate their own responses.
Sourcepub fn map_into_right_body<L>(self) -> HttpResponse<EitherBody<L, B>>
pub fn map_into_right_body<L>(self) -> HttpResponse<EitherBody<L, B>>
Map the current body type B to EitherBody::Right(B).
Useful for middleware which can generate their own responses.
Sourcepub fn map_into_boxed_body(self) -> HttpResponse<BoxBody>where
B: MessageBody + 'static,
pub fn map_into_boxed_body(self) -> HttpResponse<BoxBody>where
B: MessageBody + 'static,
Map the current body to a type-erased BoxBody.
Trait Implementations§
Source§impl<B> Debug for HttpResponse<B>where
B: MessageBody,
impl<B> Debug for HttpResponse<B>where
B: MessageBody,
Source§impl From<Error> for HttpResponse
impl From<Error> for HttpResponse
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 HttpResponse
impl From<HttpResponseBuilder> for HttpResponse
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<B> From<ServiceResponse<B>> for HttpResponse<B>
impl<B> From<ServiceResponse<B>> for HttpResponse<B>
Source§fn from(res: ServiceResponse<B>) -> HttpResponse<B>
fn from(res: ServiceResponse<B>) -> HttpResponse<B>
Source§impl<B> Responder for HttpResponse<B>where
B: MessageBody + 'static,
impl<B> Responder for HttpResponse<B>where
B: MessageBody + 'static,
type Body = B
Source§fn respond_to(self, _: &HttpRequest) -> HttpResponse<Self::Body>
fn respond_to(self, _: &HttpRequest) -> HttpResponse<Self::Body>
HttpResponse.