[][src]Struct actix_web::dev::HttpResponseBuilder

pub struct HttpResponseBuilder { /* fields omitted */ }

An HTTP response builder

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

Methods

impl HttpResponseBuilder[src]

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

Set HTTP status code of this response.

pub fn version(&mut self, version: Version) -> &mut Self[src]

Set HTTP version of this response.

By default response's http version depends on request's version.

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

Set a header.

use actix_web::{http, HttpRequest, HttpResponse};

fn index(req: HttpRequest) -> HttpResponse {
    HttpResponse::Ok()
        .header("X-TEST", "value")
        .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 content_encoding(&mut self, enc: ContentEncoding) -> &mut Self[src]

Set content encoding.

By default ContentEncoding::Auto is used, which automatically negotiates content encoding based on request's Accept-Encoding headers. To enforce specific encoding, use specific ContentEncoding` value.

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

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

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

Enables automatic chunked transfer encoding

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

Force disable chunked encoding

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 cookie<'c>(&mut self, cookie: Cookie<'c>) -> &mut Self[src]

Set a cookie

use actix_web::{http, HttpRequest, HttpResponse, Result};

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

Remove cookie

use actix_web::{http, HttpRequest, HttpResponse, Result};

fn index(req: &HttpRequest) -> HttpResponse {
    let mut builder = HttpResponse::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 Self where
    F: FnOnce(&mut HttpResponseBuilder), 
[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 HttpResponseBuilder), 
[src]

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

pub fn write_buffer_capacity(&mut self, cap: usize) -> &mut Self[src]

Set write buffer capacity

This parameter makes sense only for streaming response or actor. If write buffer reaches specified capacity, stream or actor get paused.

Default write buffer capacity is 64kb

pub fn body<B: Into<Body>>(&mut self, body: B) -> HttpResponse[src]

Set a body and generate HttpResponse.

HttpResponseBuilder can not be used after this call.

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

Set a streaming body and generate HttpResponse.

HttpResponseBuilder can not be used after this call.

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

Set a json body and generate HttpResponse

HttpResponseBuilder can not be used after this call.

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

Set a json body and generate HttpResponse

HttpResponseBuilder can not be used after this call.

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

Set an empty body and generate HttpResponse

HttpResponseBuilder can not be used after this call.

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

This method construct new HttpResponseBuilder

Trait Implementations

impl Responder for HttpResponseBuilder[src]

type Item = HttpResponse

The associated item which can be returned.

type Error = Error

The associated error which can be returned.

impl From<HttpResponseBuilder> for HttpResponse[src]

impl<'a> From<&'a ClientResponse> for HttpResponseBuilder[src]

Create HttpResponseBuilder from ClientResponse

It is useful for proxy response. This implementation copies all responses's headers and status.

impl<'a, S> From<&'a HttpRequest<S>> for HttpResponseBuilder[src]

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<T> Erased for T