Struct actix_web::HttpResponse

source ·
pub struct HttpResponse<B = BoxBody> { /* private fields */ }
Expand description

An outgoing response.

Implementations§

source§

impl HttpResponse

source

pub fn Continue() -> HttpResponseBuilder

source

pub fn SwitchingProtocols() -> HttpResponseBuilder

source

pub fn Processing() -> HttpResponseBuilder

source

pub fn Ok() -> HttpResponseBuilder

source

pub fn Created() -> HttpResponseBuilder

source

pub fn Accepted() -> HttpResponseBuilder

source

pub fn NonAuthoritativeInformation() -> HttpResponseBuilder

source

pub fn NoContent() -> HttpResponseBuilder

source

pub fn ResetContent() -> HttpResponseBuilder

source

pub fn PartialContent() -> HttpResponseBuilder

source

pub fn MultiStatus() -> HttpResponseBuilder

source

pub fn AlreadyReported() -> HttpResponseBuilder

source

pub fn ImUsed() -> HttpResponseBuilder

source

pub fn MultipleChoices() -> HttpResponseBuilder

source

pub fn MovedPermanently() -> HttpResponseBuilder

source

pub fn Found() -> HttpResponseBuilder

source

pub fn SeeOther() -> HttpResponseBuilder

source

pub fn NotModified() -> HttpResponseBuilder

source

pub fn UseProxy() -> HttpResponseBuilder

source

pub fn TemporaryRedirect() -> HttpResponseBuilder

source

pub fn PermanentRedirect() -> HttpResponseBuilder

source

pub fn BadRequest() -> HttpResponseBuilder

source

pub fn Unauthorized() -> HttpResponseBuilder

source

pub fn PaymentRequired() -> HttpResponseBuilder

source

pub fn Forbidden() -> HttpResponseBuilder

source

pub fn NotFound() -> HttpResponseBuilder

source

pub fn MethodNotAllowed() -> HttpResponseBuilder

source

pub fn NotAcceptable() -> HttpResponseBuilder

source

pub fn ProxyAuthenticationRequired() -> HttpResponseBuilder

source

pub fn RequestTimeout() -> HttpResponseBuilder

source

pub fn Conflict() -> HttpResponseBuilder

source

pub fn Gone() -> HttpResponseBuilder

source

pub fn LengthRequired() -> HttpResponseBuilder

source

pub fn PreconditionFailed() -> HttpResponseBuilder

source

pub fn PayloadTooLarge() -> HttpResponseBuilder

source

pub fn UriTooLong() -> HttpResponseBuilder

source

pub fn UnsupportedMediaType() -> HttpResponseBuilder

source

pub fn RangeNotSatisfiable() -> HttpResponseBuilder

source

pub fn ExpectationFailed() -> HttpResponseBuilder

source

pub fn ImATeapot() -> HttpResponseBuilder

source

pub fn MisdirectedRequest() -> HttpResponseBuilder

source

pub fn UnprocessableEntity() -> HttpResponseBuilder

source

pub fn Locked() -> HttpResponseBuilder

source

pub fn FailedDependency() -> HttpResponseBuilder

source

pub fn UpgradeRequired() -> HttpResponseBuilder

source

pub fn PreconditionRequired() -> HttpResponseBuilder

source

pub fn TooManyRequests() -> HttpResponseBuilder

source

pub fn RequestHeaderFieldsTooLarge() -> HttpResponseBuilder

source

pub fn UnavailableForLegalReasons() -> HttpResponseBuilder

source

pub fn InternalServerError() -> HttpResponseBuilder

source

pub fn NotImplemented() -> HttpResponseBuilder

source

pub fn BadGateway() -> HttpResponseBuilder

source

pub fn ServiceUnavailable() -> HttpResponseBuilder

source

pub fn GatewayTimeout() -> HttpResponseBuilder

source

pub fn VersionNotSupported() -> HttpResponseBuilder

source

pub fn VariantAlsoNegotiates() -> HttpResponseBuilder

source

pub fn InsufficientStorage() -> HttpResponseBuilder

source

pub fn LoopDetected() -> HttpResponseBuilder

source

pub fn NotExtended() -> HttpResponseBuilder

source

pub fn NetworkAuthenticationRequired() -> HttpResponseBuilder

source§

impl HttpResponse<BoxBody>

source

pub fn new(status: StatusCode) -> Self

Constructs a response.

source

pub fn build(status: StatusCode) -> HttpResponseBuilder

Constructs a response builder with specific HTTP status.

source

pub fn from_error(error: impl Into<Error>) -> Self

Create an error response.

source§

impl<B> HttpResponse<B>

source

pub fn with_body(status: StatusCode, body: B) -> Self

Constructs a response with body

source

pub fn head(&self) -> &ResponseHead

Returns a reference to response head.

source

pub fn head_mut(&mut self) -> &mut ResponseHead

Returns a mutable reference to response head.

source

pub fn error(&self) -> Option<&Error>

The source error for this response

source

pub fn status(&self) -> StatusCode

Get the response status code

source

pub fn status_mut(&mut self) -> &mut StatusCode

Set the StatusCode for this response

source

pub fn headers(&self) -> &HeaderMap

Get the headers from the response

source

pub fn headers_mut(&mut self) -> &mut HeaderMap

Get a mutable reference to the headers

source

pub fn cookies(&self) -> CookieIter<'_>

Available on crate feature cookies only.

Get an iterator for the cookies set by this response.

Available on crate feature 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.

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.

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.

source

pub fn upgrade(&self) -> bool

Connection upgrade status

source

pub fn keep_alive(&self) -> bool

Keep-alive status for this connection

source

pub fn extensions(&self) -> Ref<'_, Extensions>

Returns reference to the response-local data/extensions container.

source

pub fn extensions_mut(&mut self) -> RefMut<'_, Extensions>

Returns reference to the response-local data/extensions container.

source

pub fn body(&self) -> &B

Returns a reference to this response’s body.

source

pub fn set_body<B2>(self, body: B2) -> HttpResponse<B2>

Sets new body.

source

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.

source

pub fn drop_body(self) -> HttpResponse<()>

Drops body and returns new response.

source

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.

source

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.

source

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.

source

pub fn map_into_boxed_body(self) -> HttpResponse<BoxBody>
where B: MessageBody + 'static,

Map the current body to a type-erased BoxBody.

source

pub fn into_body(self) -> B

Returns the response body, dropping all other parts.

Trait Implementations§

source§

impl<B> Debug for HttpResponse<B>
where B: MessageBody,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<Error> for HttpResponse

source§

fn from(err: Error) -> Self

Converts to this type from the input type.
source§

impl<B> From<HttpResponse<B>> for Response<B>

source§

fn from(res: HttpResponse<B>) -> Self

Converts to this type from the input type.
source§

impl From<HttpResponseBuilder> for HttpResponse

source§

fn from(builder: HttpResponseBuilder) -> Self

Converts to this type from the input type.
source§

impl<B> From<Response<B>> for HttpResponse<B>

source§

fn from(res: Response<B>) -> Self

Converts to this type from the input type.
source§

impl<B> From<ServiceResponse<B>> for HttpResponse<B>

source§

fn from(res: ServiceResponse<B>) -> HttpResponse<B>

Converts to this type from the input type.
source§

impl<B> Responder for HttpResponse<B>
where B: MessageBody + 'static,

§

type Body = B

source§

fn respond_to(self, _: &HttpRequest) -> HttpResponse<Self::Body>

Convert self to HttpResponse.
source§

fn customize(self) -> CustomizeResponder<Self>
where Self: Sized,

Wraps responder to allow alteration of its response. Read more

Auto Trait Implementations§

§

impl<B = BoxBody> !Freeze for HttpResponse<B>

§

impl<B = BoxBody> !RefUnwindSafe for HttpResponse<B>

§

impl<B = BoxBody> !Send for HttpResponse<B>

§

impl<B = BoxBody> !Sync for HttpResponse<B>

§

impl<B> Unpin for HttpResponse<B>
where B: Unpin,

§

impl<B = BoxBody> !UnwindSafe for HttpResponse<B>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more