[][src]Struct actix_http::ResponseBuilder

pub struct ResponseBuilder { /* 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[src]

pub fn new(status: StatusCode) -> Self[src]

Create response builder

pub fn status(&mut self, status: StatusCode) -> &mut Self[src]

Set HTTP status code of this response.

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

Append a header to existing headers.

This example is not tested
use actix_web::{http, Request, Response};

fn index(req: HttpRequest) -> 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 Self where
    HeaderName: HttpTryFrom<K>,
    V: IntoHeaderValue, 
[src]

Set a header.

This example is not tested
use actix_web::{http, Request, Response};

fn index(req: HttpRequest) -> 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 Self[src]

Set the custom reason for the response.

pub fn keep_alive(&mut self) -> &mut Self[src]

Set connection type to KeepAlive

pub fn upgrade<V>(&mut self, value: V) -> &mut Self where
    V: IntoHeaderValue, 
[src]

Set connection type to Upgrade

pub fn force_close(&mut self) -> &mut Self[src]

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

pub fn no_chunking(&mut self) -> &mut Self[src]

Disable chunked transfer encoding for HTTP/1.1 streaming responses.

pub fn content_type<V>(&mut self, value: V) -> &mut Self where
    HeaderValue: HttpTryFrom<V>, 
[src]

Set response content type

pub fn content_length(&mut self, len: u64) -> &mut Self[src]

Set content length

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

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 Self where
    F: FnOnce(T, &mut ResponseBuilder), 
[src]

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

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: Into<Body>>(&mut self, body: B) -> Response[src]

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>[src]

Set a body and generate Response.

ResponseBuilder can not be used after this call.

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

Set a streaming body and generate Response.

ResponseBuilder can not be used after this call.

pub fn json<T: Serialize>(&mut self, value: T) -> Response[src]

Set a json body and generate Response

ResponseBuilder can not be used after this call.

pub fn json2<T: Serialize>(&mut self, value: &T) -> Response[src]

Set a json body and generate Response

ResponseBuilder can not be used after this call.

pub fn finish(&mut self) -> Response[src]

Set an empty body and generate Response

ResponseBuilder can not be used after this call.

pub fn take(&mut self) -> ResponseBuilder[src]

This method construct new ResponseBuilder

Trait Implementations

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

Convert Response to a ResponseBuilder. Body get dropped.

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

Convert ResponseHead to a ResponseBuilder

impl From<ResponseBuilder> for Response[src]

impl IntoFuture for ResponseBuilder[src]

type Item = Response

The item that the future may resolve with.

type Error = Error

The error that the future may resolve with.

type Future = FutureResult<Response, Error>

The future that this type can be converted into.

Auto Trait Implementations

Blanket Implementations

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

impl<T> From for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

impl<T, U> TryInto 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<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<T> Erased for T