Struct actix_web::dev::BaseHttpResponseBuilder[][src]

pub struct BaseHttpResponseBuilder { /* fields omitted */ }

An HTTP response builder.

Used to construct an instance of Response using a builder pattern. Response builders are often created using Response::build.

Examples

use actix_http::{Response, ResponseBuilder, body, http::StatusCode, http::header};

let mut res: Response<_> = Response::build(StatusCode::OK)
    .content_type(mime::APPLICATION_JSON)
    .insert_header((header::SERVER, "my-app/1.0"))
    .append_header((header::SET_COOKIE, "a=1"))
    .append_header((header::SET_COOKIE, "b=2"))
    .body("1234");

assert_eq!(res.status(), StatusCode::OK);
assert_eq!(body::to_bytes(res.take_body()).await.unwrap(), &b"1234"[..]);

assert!(res.headers().contains_key("server"));
assert_eq!(res.headers().get_all("set-cookie").count(), 2);

Implementations

impl ResponseBuilder[src]

pub fn new(status: StatusCode) -> ResponseBuilder

Notable traits for ResponseBuilder

impl Future for ResponseBuilder type Output = Result<Response<Body>, Error>;
[src]

Create response builder

Examples

use actix_http::{Response, ResponseBuilder, http::StatusCode};

let res: Response<_> = ResponseBuilder::default().finish();
assert_eq!(res.status(), StatusCode::OK);

pub fn status(&mut self, status: StatusCode) -> &mut ResponseBuilder

Notable traits for ResponseBuilder

impl Future for ResponseBuilder type Output = Result<Response<Body>, Error>;
[src]

Set HTTP status code of this response.

Examples

use actix_http::{ResponseBuilder, http::StatusCode};

let res = ResponseBuilder::default().status(StatusCode::NOT_FOUND).finish();
assert_eq!(res.status(), StatusCode::NOT_FOUND);

pub fn insert_header<H>(&mut self, header: H) -> &mut ResponseBuilder

Notable traits for ResponseBuilder

impl Future for ResponseBuilder type Output = Result<Response<Body>, Error>;
where
    H: IntoHeaderPair
[src]

Insert a header, replacing any that were set with an equivalent field name.

Examples

use actix_http::{ResponseBuilder, http::header};

let res = ResponseBuilder::default()
    .insert_header((header::CONTENT_TYPE, mime::APPLICATION_JSON))
    .insert_header(("X-TEST", "value"))
    .finish();

assert!(res.headers().contains_key("content-type"));
assert!(res.headers().contains_key("x-test"));

pub fn append_header<H>(&mut self, header: H) -> &mut ResponseBuilder

Notable traits for ResponseBuilder

impl Future for ResponseBuilder type Output = Result<Response<Body>, Error>;
where
    H: IntoHeaderPair
[src]

Append a header, keeping any that were set with an equivalent field name.

Examples

use actix_http::{ResponseBuilder, http::header};

let res = ResponseBuilder::default()
    .append_header((header::CONTENT_TYPE, mime::APPLICATION_JSON))
    .append_header(("X-TEST", "value1"))
    .append_header(("X-TEST", "value2"))
    .finish();

assert_eq!(res.headers().get_all("content-type").count(), 1);
assert_eq!(res.headers().get_all("x-test").count(), 2);

pub fn reason(&mut self, reason: &'static str) -> &mut ResponseBuilder

Notable traits for ResponseBuilder

impl Future for ResponseBuilder type Output = Result<Response<Body>, Error>;
[src]

Set the custom reason for the response.

pub fn keep_alive(&mut self) -> &mut ResponseBuilder

Notable traits for ResponseBuilder

impl Future for ResponseBuilder type Output = Result<Response<Body>, Error>;
[src]

Set connection type to KeepAlive

pub fn upgrade<V>(&mut self, value: V) -> &mut ResponseBuilder

Notable traits for ResponseBuilder

impl Future for ResponseBuilder type Output = Result<Response<Body>, Error>;
where
    V: IntoHeaderValue
[src]

Set connection type to Upgrade

pub fn force_close(&mut self) -> &mut ResponseBuilder

Notable traits for ResponseBuilder

impl Future for ResponseBuilder type Output = Result<Response<Body>, Error>;
[src]

Force close connection, even if it is marked as keep-alive

pub fn no_chunking(&mut self, len: u64) -> &mut ResponseBuilder

Notable traits for ResponseBuilder

impl Future for ResponseBuilder type Output = Result<Response<Body>, Error>;
[src]

Disable chunked transfer encoding for HTTP/1.1 streaming responses.

pub fn content_type<V>(&mut self, value: V) -> &mut ResponseBuilder

Notable traits for ResponseBuilder

impl Future for ResponseBuilder type Output = Result<Response<Body>, Error>;
where
    V: IntoHeaderValue
[src]

Set response content type.

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

Responses extensions

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

Mutable reference to a the response’s extensions

pub fn body<B>(&mut self, body: B) -> Response<Body>

Notable traits for Response<B>

impl<B> Future for Response<B> where
    B: Unpin
type Output = Result<Response<B>, Error>;
where
    B: Into<Body>, 
[src]

Generate response with a wrapped body.

This ResponseBuilder will be left in a useless state.

pub fn message_body<B>(&mut self, body: B) -> Response<B>

Notable traits for Response<B>

impl<B> Future for Response<B> where
    B: Unpin
type Output = Result<Response<B>, Error>;
[src]

Generate response with a body.

This ResponseBuilder will be left in a useless state.

pub fn streaming<S, E>(&mut self, stream: S) -> Response<Body>

Notable traits for Response<B>

impl<B> Future for Response<B> where
    B: Unpin
type Output = Result<Response<B>, Error>;
where
    E: Into<Error> + 'static,
    S: Stream<Item = Result<Bytes, E>> + Unpin + 'static, 
[src]

Generate response with a streaming body.

This ResponseBuilder will be left in a useless state.

pub fn finish(&mut self) -> Response<Body>

Notable traits for Response<B>

impl<B> Future for Response<B> where
    B: Unpin
type Output = Result<Response<B>, Error>;
[src]

Generate response with an empty body.

This ResponseBuilder will be left in a useless state.

pub fn take(&mut self) -> ResponseBuilder

Notable traits for ResponseBuilder

impl Future for ResponseBuilder type Output = Result<Response<Body>, Error>;
[src]

Create an owned ResponseBuilder, leaving the original in a useless state.

Trait Implementations

impl BodyEncoding for ResponseBuilder[src]

impl Debug for ResponseBuilder[src]

impl Default for ResponseBuilder[src]

impl<'a> From<&'a ResponseHead> for ResponseBuilder[src]

Convert ResponseHead to a ResponseBuilder

impl<B> From<Response<B>> for ResponseBuilder[src]

Convert Response to a ResponseBuilder. Body get dropped.

impl From<ResponseBuilder> for Error[src]

Convert ResponseBuilder to a Error

impl From<ResponseBuilder> for Response<Body>[src]

impl Future for ResponseBuilder[src]

type Output = Result<Response<Body>, Error>

The type of value produced on completion.

impl Responder for ResponseBuilder[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> FutureExt for T where
    T: Future + ?Sized
[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<F> IntoFuture for F where
    F: Future
[src]

type Output = <F as Future>::Output

🔬 This is a nightly-only experimental API. (into_future)

The output that the future will produce on completion.

type Future = F

🔬 This is a nightly-only experimental API. (into_future)

Which kind of future are we turning this into?

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<F, T, E> TryFuture for F where
    F: Future<Output = Result<T, E>> + ?Sized
[src]

type Ok = T

The type of successful values yielded by this future

type Error = E

The type of failures yielded by this future

impl<Fut> TryFutureExt for Fut where
    Fut: TryFuture + ?Sized
[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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