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

Set HTTP status code of this response.

Set HTTP version of this response.

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

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() {}

Set the custom reason for the response.

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.

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

Enables automatic chunked transfer encoding

Force disable chunked encoding

Set response content type

Set content length

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()
}

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

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

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

Set a body and generate HttpResponse.

HttpResponseBuilder can not be used after this call.

Set a streaming body and generate HttpResponse.

HttpResponseBuilder can not be used after this call.

Set a json body and generate HttpResponse

HttpResponseBuilder can not be used after this call.

Set a json body and generate HttpResponse

HttpResponseBuilder can not be used after this call.

Set an empty body and generate HttpResponse

HttpResponseBuilder can not be used after this call.

This method construct new HttpResponseBuilder

Trait Implementations

impl Responder for HttpResponseBuilder
[src]

The associated item which can be returned.

The associated error which can be returned.

Convert itself to AsyncResult or Error.

impl From<HttpResponseBuilder> for HttpResponse
[src]

Performs the conversion.

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.

Performs the conversion.

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

Performs the conversion.

Auto Trait Implementations

impl !Send for HttpResponseBuilder

impl !Sync for HttpResponseBuilder

Blanket Implementations

impl<T> From for T
[src]

Performs the conversion.

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

Performs the conversion.

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

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

The type returned in the event of a conversion error.

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

Performs the conversion.

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

Immutably borrows from an owned value. Read more

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

Mutably borrows from an owned value. Read more

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

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

The type returned in the event of a conversion error.

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

Performs the conversion.

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

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

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more

impl<T> Erased for T