Struct ntex::web::HttpResponseBuilder[][src]

pub struct HttpResponseBuilder { /* fields omitted */ }
Expand description

An HTTP response builder

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

Implementations

Create response builder

Set HTTP status code of this response.

Append a header to existing headers.

use ntex::http::{header, Request, Response};

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

Set a header.

use ntex::http::{header, Request, Response};

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

Set the custom reason for the response.

Set connection type to KeepAlive

Set connection type to Upgrade

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

Disable chunked transfer encoding for HTTP/1.1 streaming responses.

Set response content type

Set content length

Set a cookie

use coo_kie as cookie;
use ntex::http::{Request, Response};

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

Remove cookie

use ntex::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()
}

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

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

Responses extensions

Mutable reference to a the response’s extensions

Set a body and generate Response.

ResponseBuilder can not be used after this call.

Set a body and generate Response.

ResponseBuilder can not be used after this call.

Set a streaming body and generate Response.

ResponseBuilder can not be used after this call.

Set a json body and generate Response

ResponseBuilder can not be used after this call.

Set an empty body and generate Response

ResponseBuilder can not be used after this call.

This method construct new ResponseBuilder

Trait Implementations

Get content encoding

Set content encoding

Formats the value using the given formatter. Read more

Convert ResponseHead to a ResponseBuilder

Performs the conversion.

Convert Response to a ResponseBuilder. Body get dropped.

Performs the conversion.

Performs the conversion.

The associated error which can be returned.

The future response value.

Convert itself to AsyncResult or Error.

Override a status code for a Responder. Read more

Add header to the Responder’s response. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more