[]Struct actix_web::dev::HttpResponseBuilder

pub struct HttpResponseBuilder { /* fields omitted */ }

An HTTP response builder

This type can be used to construct an instance of Response through a builder-like pattern.

Methods

impl ResponseBuilder

pub fn new(status: StatusCode) -> ResponseBuilder

Create response builder

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

Set HTTP status code of this response.

pub fn header<K, V>(&mut self, key: K, value: V) -> &mut ResponseBuilder where
    V: IntoHeaderValue,
    HeaderName: HttpTryFrom<K>, 

Append a header to existing headers.

use actix_http::{http, Request, Response};

fn index(req: Request) -> Response {
    Response::Ok()
        .header("X-TEST", "value")
        .header(http::header::CONTENT_TYPE, "application/json")
        .finish()
}
fn main() {}

pub fn set_header<K, V>(&mut self, key: K, value: V) -> &mut ResponseBuilder where
    V: IntoHeaderValue,
    HeaderName: HttpTryFrom<K>, 

Set a header.

use actix_http::{http, Request, Response};

fn index(req: Request) -> Response {
    Response::Ok()
        .set_header("X-TEST", "value")
        .set_header(http::header::CONTENT_TYPE, "application/json")
        .finish()
}
fn main() {}

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

Set the custom reason for the response.

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

Set connection type to KeepAlive

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

Set connection type to Upgrade

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

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

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

Disable chunked transfer encoding for HTTP/1.1 streaming responses.

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

Set response content type

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

Set content length

pub fn cookie(&mut self, cookie: Cookie<'c>) -> &mut ResponseBuilder

Set a cookie

use actix_http::{http, Request, Response};

fn index(req: Request) -> Response {
    Response::Ok()
        .cookie(
            http::Cookie::build("name", "value")
                .domain("www.rust-lang.org")
                .path("/")
                .secure(true)
                .http_only(true)
                .finish(),
        )
        .finish()
}

Remove cookie

use actix_http::{http, Request, Response, HttpMessage};

fn index(req: Request) -> Response {
    let mut builder = Response::Ok();

    if let Some(ref cookie) = req.cookie("name") {
        builder.del_cookie(cookie);
    }

    builder.finish()
}

pub fn if_true<F>(&mut self, value: bool, f: F) -> &mut ResponseBuilder where
    F: FnOnce(&mut ResponseBuilder), 

This method calls provided closure with builder reference if value is true.

pub fn if_some<T, F>(&mut self, value: Option<T>, f: F) -> &mut ResponseBuilder where
    F: FnOnce(T, &mut ResponseBuilder), 

This method calls provided closure with builder reference if value is Some.

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

Responses extensions

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

Mutable reference to a the response's extensions

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

Set a body and generate Response.

ResponseBuilder can not be used after this call.

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

Set a body and generate Response.

ResponseBuilder can not be used after this call.

pub fn streaming<S, E>(&mut self, stream: S) -> Response<Body> where
    E: Into<Error> + 'static,
    S: Stream<Item = Bytes, Error = E> + 'static, 

Set a streaming body and generate Response.

ResponseBuilder can not be used after this call.

pub fn json<T>(&mut self, value: T) -> Response<Body> where
    T: Serialize

Set a json body and generate Response

ResponseBuilder can not be used after this call.

pub fn json2<T>(&mut self, value: &T) -> Response<Body> where
    T: Serialize

Set a json body and generate Response

ResponseBuilder can not be used after this call.

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

Set an empty body and generate Response

ResponseBuilder can not be used after this call.

pub fn take(&mut self) -> ResponseBuilder

This method construct new ResponseBuilder

Trait Implementations

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

Convert Response to a ResponseBuilder. Body get dropped.

impl From<ResponseBuilder> for Response<Body>

impl<'a> From<&'a ResponseHead> for ResponseBuilder

Convert ResponseHead to a ResponseBuilder

impl Debug for ResponseBuilder

impl IntoFuture for ResponseBuilder

type Item = Response<Body>

The item that the future may resolve with.

type Error = Error

The error that the future may resolve with.

type Future = FutureResult<Response<Body>, Error>

The future that this type can be converted into.

impl BodyEncoding for ResponseBuilder[src]

impl Responder for ResponseBuilder[src]

type Error = Error

The associated error which can be returned.

type Future = FutureResult<Response, Error>

The future response value.

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

Override a status code for a Responder. Read more

fn with_header<K, V>(self, key: K, value: V) -> CustomResponder<Self> where
    Self: Sized,
    HeaderName: HttpTryFrom<K>,
    V: IntoHeaderValue
[src]

Add header to the Responder's response. Read more

Auto Trait Implementations

impl Unpin for ResponseBuilder

impl !Sync for ResponseBuilder

impl !Send for ResponseBuilder

impl !UnwindSafe for ResponseBuilder

impl !RefUnwindSafe for ResponseBuilder

Blanket Implementations

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

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

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<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<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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

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

type Future = F

The future that this type can be converted into.

type Item = <F as Future>::Item

The item that the future may resolve with.

type Error = <F as Future>::Error

The error that the future may resolve with.

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