Struct actix_http::Response

source ·
pub struct Response<B> { /* private fields */ }
Expand description

An HTTP response.

Implementations§

source§

impl Response<BoxBody>

source

pub fn new(status: StatusCode) -> Self

Constructs a new response with default body.

source

pub fn build(status: StatusCode) -> ResponseBuilder

Constructs a new response builder.

source

pub fn ok() -> Self

Constructs a new response with status 200 OK.

source

pub fn bad_request() -> Self

Constructs a new response with status 400 Bad Request.

source

pub fn not_found() -> Self

Constructs a new response with status 404 Not Found.

source

pub fn internal_server_error() -> Self

Constructs a new response with status 500 Internal Server Error.

source§

impl<B> Response<B>

source

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

Constructs a new response with given body.

source

pub fn head(&self) -> &ResponseHead

Returns a reference to the head of this response.

source

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

Returns a mutable reference to the head of this response.

source

pub fn status(&self) -> StatusCode

Returns the status code of this response.

source

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

Returns a mutable reference the status code of this response.

source

pub fn headers(&self) -> &HeaderMap

Returns a reference to response headers.

source

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

Returns a mutable reference to response headers.

source

pub fn upgrade(&self) -> bool

Returns true if connection upgrade is enabled.

source

pub fn keep_alive(&self) -> bool

Returns true if keep-alive is enabled.

source

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

Returns a reference to the request-local data/extensions container.

source

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

Returns a mutable reference to the request-local data/extensions container.

source

pub fn body(&self) -> &B

Returns a reference to the body of this response.

source

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

Sets new body.

source

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

Drops body and returns new response.

source

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.

source

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.

source

pub fn map_into_boxed_body(self) -> Response<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 Response<B>
where B: MessageBody,

source§

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

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

impl<B: Default> Default for Response<B>

source§

fn default() -> Response<B>

Returns the “default value” for a type. Read more
source§

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

source§

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

Converts to this type from the input type.
source§

impl From<&HandshakeError> for Response<BoxBody>

source§

fn from(err: &HandshakeError) -> Self

Converts to this type from the input type.
source§

impl From<&String> for Response<String>

source§

fn from(val: &String) -> Self

Converts to this type from the input type.
source§

impl From<&Vec<u8>> for Response<Vec<u8>>

source§

fn from(val: &Vec<u8>) -> Self

Converts to this type from the input type.
source§

impl From<&'static str> for Response<&'static str>

source§

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

Converts to this type from the input type.
source§

impl From<ByteString> for Response<ByteString>

source§

fn from(val: ByteString) -> Self

Converts to this type from the input type.
source§

impl From<Bytes> for Response<Bytes>

source§

fn from(val: Bytes) -> Self

Converts to this type from the input type.
source§

impl From<BytesMut> for Response<BytesMut>

source§

fn from(val: BytesMut) -> Self

Converts to this type from the input type.
source§

impl From<Error> for Response<BoxBody>

source§

fn from(err: Error) -> Self

Converts to this type from the input type.
source§

impl From<HandshakeError> for Response<BoxBody>

source§

fn from(err: HandshakeError) -> Self

Converts to this type from the input type.
source§

impl From<Infallible> for Response<BoxBody>

source§

fn from(val: Infallible) -> Self

Converts to this type from the input type.
source§

impl From<ParseError> for Response<BoxBody>

source§

fn from(err: ParseError) -> 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<Response<BoxBody>> for DispatchError

source§

fn from(original: Response<BoxBody>) -> DispatchError

Converts to this type from the input type.
source§

impl From<ResponseBuilder> for Response<EitherBody<()>>

source§

fn from(builder: ResponseBuilder) -> Self

Converts to this type from the input type.
source§

impl<I: Into<Response<BoxBody>>, E: Into<Error>> From<Result<I, E>> for Response<BoxBody>

source§

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

Converts to this type from the input type.
source§

impl From<String> for Response<String>

source§

fn from(val: String) -> Self

Converts to this type from the input type.
source§

impl From<Vec<u8>> for Response<Vec<u8>>

source§

fn from(val: Vec<u8>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<B> !Freeze for Response<B>

§

impl<B> !RefUnwindSafe for Response<B>

§

impl<B> !Send for Response<B>

§

impl<B> !Sync for Response<B>

§

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

§

impl<B> !UnwindSafe for Response<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

source§

type Output = T

Should always be Self
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.
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