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

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]

Important traits for &'a mut R

Set HTTP status code of this response.

Important traits for &'a mut R

Set HTTP version of this response.

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

Important traits for &'a mut R

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

Important traits for &'a mut R

Set the custom reason for the response.

Important traits for &'a mut R

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.

Important traits for &'a mut R

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

Important traits for &'a mut R

Enables automatic chunked transfer encoding

Important traits for &'a mut R

Force disable chunked encoding

Important traits for &'a mut R

Set response content type

Important traits for &'a mut R

Set content length

Important traits for &'a mut R

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

Important traits for &'a mut R

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

Important traits for &'a mut R

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

Important traits for &'a mut R

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 an empty body and generate HttpResponse

HttpResponseBuilder can not be used after this call.

This method construct new HttpResponseBuilder

Trait Implementations

impl From<HttpResponseBuilder> for HttpResponse
[src]

Performs the conversion.

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<'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