Skip to main content

Response

Struct Response 

Source
pub struct Response<B = Body> { /* private fields */ }
Expand description

An HTTP response.

Implementations§

Source§

impl Response

Source

pub fn Ok() -> ResponseBuilder

Source

pub fn Created() -> ResponseBuilder

Source

pub fn Accepted() -> ResponseBuilder

Source

pub fn NonAuthoritativeInformation() -> ResponseBuilder

Source

pub fn NoContent() -> ResponseBuilder

Source

pub fn ResetContent() -> ResponseBuilder

Source

pub fn PartialContent() -> ResponseBuilder

Source

pub fn MultiStatus() -> ResponseBuilder

Source

pub fn AlreadyReported() -> ResponseBuilder

Source

pub fn MultipleChoices() -> ResponseBuilder

Source

pub fn MovedPermanently() -> ResponseBuilder

Source

pub fn Found() -> ResponseBuilder

Source

pub fn SeeOther() -> ResponseBuilder

Source

pub fn NotModified() -> ResponseBuilder

Source

pub fn UseProxy() -> ResponseBuilder

Source

pub fn TemporaryRedirect() -> ResponseBuilder

Source

pub fn PermanentRedirect() -> ResponseBuilder

Source

pub fn BadRequest() -> ResponseBuilder

Source

pub fn NotFound() -> ResponseBuilder

Source

pub fn Unauthorized() -> ResponseBuilder

Source

pub fn PaymentRequired() -> ResponseBuilder

Source

pub fn Forbidden() -> ResponseBuilder

Source

pub fn MethodNotAllowed() -> ResponseBuilder

Source

pub fn NotAcceptable() -> ResponseBuilder

Source

pub fn ProxyAuthenticationRequired() -> ResponseBuilder

Source

pub fn RequestTimeout() -> ResponseBuilder

Source

pub fn Conflict() -> ResponseBuilder

Source

pub fn Gone() -> ResponseBuilder

Source

pub fn LengthRequired() -> ResponseBuilder

Source

pub fn PreconditionFailed() -> ResponseBuilder

Source

pub fn PreconditionRequired() -> ResponseBuilder

Source

pub fn PayloadTooLarge() -> ResponseBuilder

Source

pub fn UriTooLong() -> ResponseBuilder

Source

pub fn UnsupportedMediaType() -> ResponseBuilder

Source

pub fn RangeNotSatisfiable() -> ResponseBuilder

Source

pub fn ExpectationFailed() -> ResponseBuilder

Source

pub fn MisdirectedRequest() -> ResponseBuilder

Source

pub fn UnprocessableEntity() -> ResponseBuilder

Source

pub fn Locaked() -> ResponseBuilder

Source

pub fn FailedDependency() -> ResponseBuilder

Source

pub fn TooEarly() -> ResponseBuilder

Source

pub fn UpgradeRequired() -> ResponseBuilder

Source

pub fn TooManyRequests() -> ResponseBuilder

Source

pub fn RequestHeaderFieldsTooLarge() -> ResponseBuilder

Source

pub fn InternalServerError() -> ResponseBuilder

Source

pub fn NotImplemented() -> ResponseBuilder

Source

pub fn BadGateway() -> ResponseBuilder

Source

pub fn ServiceUnavailable() -> ResponseBuilder

Source

pub fn GatewayTimeout() -> ResponseBuilder

Source

pub fn VersionNotSupported() -> ResponseBuilder

Source

pub fn VariantAlsoNegotiates() -> ResponseBuilder

Source

pub fn InsufficientStorage() -> ResponseBuilder

Source

pub fn LoopDetected() -> ResponseBuilder

Source§

impl Response<Body>

Source

pub fn builder(status: StatusCode) -> ResponseBuilder

Creates a response builder with the given status.

Source

pub fn builder_from<T: Into<ResponseBuilder>>(source: T) -> ResponseBuilder

Creates a response builder from another compatible value.

Source

pub fn new(status: StatusCode) -> Response

Constructs a response.

Source

pub fn render_with<B: Display>(status: StatusCode, body: &B) -> Response

Renders a displayable value as a plain-text response body.

Source

pub fn into_body<B>(self) -> Response<B>

Converts the default body into a custom response body type.

Source§

impl<B> Response<B>

Source

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

Creates a response with the given status and body.

Source

pub fn head(&self) -> &ResponseHead

Returns the response head.

Source

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

Returns mutable access to the response head.

Source

pub fn status(&self) -> StatusCode

Returns the response status code.

Source

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

Returns mutable access to the response status code.

Source

pub fn headers(&self) -> &HeaderMap

Returns the response headers.

Source

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

Returns mutable access to the response headers.

Source

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

Get an iterator for the cookies set by this response.

Add a cookie to this response.

Remove all cookies with the given name from this response.

Returns the number of cookies removed.

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 the response extensions.

Source

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

Returns mutable access to the response extensions.

Source

pub fn body(&self) -> &ResponseBody<B>

Returns the response body.

Source

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

Replaces the response body with a different body type.

Source

pub fn into_parts(self) -> (Response<()>, ResponseBody<B>)

Splits the response into its metadata and body.

Source

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

Drops the response body while preserving the response head.

Source

pub fn map_body<F, B2>(self, f: F) -> Response<B2>
where F: FnOnce(&mut ResponseHead, ResponseBody<B>) -> ResponseBody<B2>,

Transforms the response body and allows its metadata to be updated.

Source

pub fn take_body(&mut self) -> ResponseBody<B>

Takes the response body, leaving an empty body behind.

Source§

impl Response<Body>

Source

pub fn take(&mut self) -> Response

Takes the response body while preserving its metadata.

The returned response contains the original body and a copy of the response head without its extensions. This response is left with an empty body, both responses can be modified independently.

Trait Implementations§

Source§

impl<B> BodyEncoding for HttpResponse<B>

Source§

fn get_encoding(&self) -> Option<ContentEncoding>

Get content encoding
Source§

fn encoding(&mut self, encoding: ContentEncoding) -> &mut Self

Set content encoding
Source§

impl<B: MessageBody> Debug for Response<B>

Source§

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

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

impl<B: MessageBody> Display for Response<B>

Source§

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

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

impl<B: MessageBody> Error for Response<B>

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl<'a> From<&'a String> for Response

Source§

fn from(val: &'a String) -> Self

Converts to this type from the input type.
Source§

impl From<&'static [u8]> for Response

Source§

fn from(val: &'static [u8]) -> Self

Converts to this type from the input type.
Source§

impl From<&'static str> for Response

Source§

fn from(val: &'static str) -> Self

Converts to this type from the input type.
Source§

impl From<Bytes> for Response

Source§

fn from(val: Bytes) -> Self

Converts to this type from the input type.
Source§

impl From<BytesMut> for Response

Source§

fn from(val: BytesMut) -> Self

Converts to this type from the input type.
Source§

impl<B> From<Response<B>> for ResponseBuilder

Convert Response to a ResponseBuilder. Body get dropped.

Source§

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

Converts to this type from the input type.
Source§

impl From<ResponseBuilder> for Response

Source§

fn from(builder: ResponseBuilder) -> Self

Converts to this type from the input type.
Source§

impl<I: Into<Response>, E> From<Result<I, E>> for Response
where E: ResponseError + Debug,

Helper converters

Source§

fn from(res: Result<I, E>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Response

Source§

fn from(val: String) -> Self

Converts to this type from the input type.
Source§

impl<T: ResponseError> From<T> for Response

Source§

fn from(err: T) -> Response

Converts to this type from the input type.
Source§

impl From<WebResponse> for Response<Body>

Source§

fn from(res: WebResponse) -> Response<Body>

Converts to this type from the input type.
Source§

impl<St: State> Responder<St> for Response

Source§

async fn respond_to(self, _: &St, _: &HttpRequest) -> Response

Builds an HTTP response from this value.
Source§

fn with_status(self, status: StatusCode) -> CustomResponder<Self, St>
where Self: Sized,

Replaces the status code produced by this responder. Read more
Source§

fn with_header<K, V>(self, key: K, value: V) -> CustomResponder<Self, St>

Sets a header on the response produced by this responder. Read more

Auto Trait Implementations§

§

impl<B = Body> !RefUnwindSafe for Response<B>

§

impl<B = Body> !Send for Response<B>

§

impl<B = Body> !Sync for Response<B>

§

impl<B = Body> !UnwindSafe for Response<B>

§

impl<B> Freeze for Response<B>
where B: Freeze,

§

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

§

impl<B> UnsafeUnpin for Response<B>
where B: UnsafeUnpin,

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, 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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>,

Source§

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.