Struct ntex::http::ResponseBuilder [−][src]
pub struct ResponseBuilder { /* 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.
pub fn header<K, V>(&mut self, key: K, value: V) -> &mut Self where
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
pub fn header<K, V>(&mut self, key: K, value: V) -> &mut Self where
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
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()
}
pub fn set_header<K, V>(&mut self, key: K, value: V) -> &mut Self where
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
pub fn set_header<K, V>(&mut self, key: K, value: V) -> &mut Self where
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
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
pub fn upgrade<V>(&mut self, value: V) -> &mut Self where
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
pub fn upgrade<V>(&mut self, value: V) -> &mut Self where
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
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.
pub fn content_type<V>(&mut self, value: V) -> &mut Self where
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
pub fn content_type<V>(&mut self, value: V) -> &mut Self where
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
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
Convert ResponseHead
to a ResponseBuilder
Performs the conversion.
Convert Response
to a ResponseBuilder
. Body get dropped.
Performs the conversion.
Performs the conversion.
Convert itself to AsyncResult
or Error
.
Override a status code for a Responder. Read more
fn with_header<K, V>(self, key: K, value: V) -> CustomResponder<Self, Err> where
Self: Sized,
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
fn with_header<K, V>(self, key: K, value: V) -> CustomResponder<Self, Err> where
Self: Sized,
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
Add header to the Responder’s response. Read more
Auto Trait Implementations
impl !RefUnwindSafe for ResponseBuilder
impl !Send for ResponseBuilder
impl !Sync for ResponseBuilder
impl Unpin for ResponseBuilder
impl !UnwindSafe for ResponseBuilder
Blanket Implementations
Mutably borrows from an owned value. Read more
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