Struct actix_web::HttpResponse
source · pub struct HttpResponse<B = BoxBody> { /* private fields */ }
Expand description
An outgoing response.
Implementations§
source§impl HttpResponse
impl HttpResponse
pub fn Continue() -> HttpResponseBuilder ⓘ
pub fn SwitchingProtocols() -> HttpResponseBuilder ⓘ
pub fn Processing() -> HttpResponseBuilder ⓘ
pub fn Ok() -> HttpResponseBuilder ⓘ
pub fn Created() -> HttpResponseBuilder ⓘ
pub fn Accepted() -> HttpResponseBuilder ⓘ
pub fn NonAuthoritativeInformation() -> HttpResponseBuilder ⓘ
pub fn NoContent() -> HttpResponseBuilder ⓘ
pub fn ResetContent() -> HttpResponseBuilder ⓘ
pub fn PartialContent() -> HttpResponseBuilder ⓘ
pub fn MultiStatus() -> HttpResponseBuilder ⓘ
pub fn AlreadyReported() -> HttpResponseBuilder ⓘ
pub fn MultipleChoices() -> HttpResponseBuilder ⓘ
pub fn MovedPermanently() -> HttpResponseBuilder ⓘ
pub fn Found() -> HttpResponseBuilder ⓘ
pub fn SeeOther() -> HttpResponseBuilder ⓘ
pub fn NotModified() -> HttpResponseBuilder ⓘ
pub fn UseProxy() -> HttpResponseBuilder ⓘ
pub fn TemporaryRedirect() -> HttpResponseBuilder ⓘ
pub fn PermanentRedirect() -> HttpResponseBuilder ⓘ
pub fn BadRequest() -> HttpResponseBuilder ⓘ
pub fn NotFound() -> HttpResponseBuilder ⓘ
pub fn PaymentRequired() -> HttpResponseBuilder ⓘ
pub fn Forbidden() -> HttpResponseBuilder ⓘ
pub fn MethodNotAllowed() -> HttpResponseBuilder ⓘ
pub fn NotAcceptable() -> HttpResponseBuilder ⓘ
pub fn ProxyAuthenticationRequired() -> HttpResponseBuilder ⓘ
pub fn RequestTimeout() -> HttpResponseBuilder ⓘ
pub fn Conflict() -> HttpResponseBuilder ⓘ
pub fn Gone() -> HttpResponseBuilder ⓘ
pub fn LengthRequired() -> HttpResponseBuilder ⓘ
pub fn PreconditionFailed() -> HttpResponseBuilder ⓘ
pub fn PreconditionRequired() -> HttpResponseBuilder ⓘ
pub fn PayloadTooLarge() -> HttpResponseBuilder ⓘ
pub fn UriTooLong() -> HttpResponseBuilder ⓘ
pub fn UnsupportedMediaType() -> HttpResponseBuilder ⓘ
pub fn RangeNotSatisfiable() -> HttpResponseBuilder ⓘ
pub fn ExpectationFailed() -> HttpResponseBuilder ⓘ
pub fn UnprocessableEntity() -> HttpResponseBuilder ⓘ
pub fn TooManyRequests() -> HttpResponseBuilder ⓘ
pub fn RequestHeaderFieldsTooLarge() -> HttpResponseBuilder ⓘ
pub fn InternalServerError() -> HttpResponseBuilder ⓘ
pub fn NotImplemented() -> HttpResponseBuilder ⓘ
pub fn BadGateway() -> HttpResponseBuilder ⓘ
pub fn GatewayTimeout() -> HttpResponseBuilder ⓘ
pub fn VersionNotSupported() -> HttpResponseBuilder ⓘ
pub fn VariantAlsoNegotiates() -> HttpResponseBuilder ⓘ
pub fn InsufficientStorage() -> HttpResponseBuilder ⓘ
pub fn LoopDetected() -> HttpResponseBuilder ⓘ
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
Get an iterator for the cookies set by this response.
Add a cookie to this response.
Errors
Returns an error if the cookie results in a malformed Set-Cookie
header.
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.
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
.