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
impl ResponseBuilder
[src]
impl ResponseBuilder
[src]pub fn new(status: StatusCode) -> Self
[src]
pub fn new(status: StatusCode) -> Self
[src]Create response builder
pub fn status(&mut self, status: StatusCode) -> &mut Self
[src]
pub fn status(&mut self, status: StatusCode) -> &mut Self
[src]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>,
[src]
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>,
[src]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>,
[src]
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>,
[src]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() }
pub fn reason(&mut self, reason: &'static str) -> &mut Self
[src]
pub fn reason(&mut self, reason: &'static str) -> &mut Self
[src]Set the custom reason for the response.
pub fn keep_alive(&mut self) -> &mut Self
[src]
pub fn keep_alive(&mut self) -> &mut Self
[src]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>,
[src]
pub fn upgrade<V>(&mut self, value: V) -> &mut Self where
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
[src]Set connection type to Upgrade
pub fn force_close(&mut self) -> &mut Self
[src]
pub fn force_close(&mut self) -> &mut Self
[src]Force close connection, even if it is marked as keep-alive
pub fn no_chunking(&mut self) -> &mut Self
[src]
pub fn no_chunking(&mut self) -> &mut Self
[src]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>,
[src]
pub fn content_type<V>(&mut self, value: V) -> &mut Self where
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
[src]Set response content type
pub fn content_length(&mut self, len: u64) -> &mut Self
[src]
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]
pub fn cookie<'c>(&mut self, cookie: Cookie<'c>) -> &mut Self
[src]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() }
pub fn del_cookie<'a>(&mut self, cookie: &Cookie<'a>) -> &mut Self
[src]
pub fn del_cookie<'a>(&mut self, cookie: &Cookie<'a>) -> &mut Self
[src]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() }
pub fn if_true<F>(&mut self, value: bool, f: F) -> &mut Self where
F: FnOnce(&mut ResponseBuilder),
[src]
pub fn if_true<F>(&mut self, value: bool, f: F) -> &mut Self where
F: FnOnce(&mut ResponseBuilder),
[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 ResponseBuilder),
[src]
pub fn if_some<T, F>(&mut self, value: Option<T>, f: F) -> &mut Self where
F: FnOnce(T, &mut ResponseBuilder),
[src]This method calls provided closure with builder reference if value is Some.
pub fn extensions(&self) -> Ref<'_, Extensions>
[src]
pub fn extensions(&self) -> Ref<'_, Extensions>
[src]Responses extensions
pub fn extensions_mut(&mut self) -> RefMut<'_, Extensions>
[src]
pub fn extensions_mut(&mut self) -> RefMut<'_, Extensions>
[src]Mutable reference to a the response’s extensions
pub fn body<B: Into<Body>>(&mut self, body: B) -> Response
[src]
pub fn body<B: Into<Body>>(&mut self, body: B) -> Response
[src]Set a body and generate Response
.
ResponseBuilder
can not be used after this call.
pub fn message_body<B>(&mut self, body: B) -> Response<B>
[src]
pub fn message_body<B>(&mut self, body: B) -> Response<B>
[src]Set a body and generate Response
.
ResponseBuilder
can not be used after this call.
pub fn streaming<S, E>(&mut self, stream: S) -> Response where
S: Stream<Item = Result<Bytes, E>> + Unpin + 'static,
E: Error + 'static,
[src]
pub fn streaming<S, E>(&mut self, stream: S) -> Response where
S: Stream<Item = Result<Bytes, E>> + Unpin + 'static,
E: Error + 'static,
[src]Set a streaming body and generate Response
.
ResponseBuilder
can not be used after this call.
pub fn json<T: Serialize>(&mut self, value: &T) -> Response
[src]
pub fn json<T: Serialize>(&mut self, value: &T) -> Response
[src]Set a json body and generate Response
ResponseBuilder
can not be used after this call.
pub fn finish(&mut self) -> Response
[src]
pub fn finish(&mut self) -> Response
[src]Set an empty body and generate Response
ResponseBuilder
can not be used after this call.
pub fn take(&mut self) -> ResponseBuilder
[src]
pub fn take(&mut self) -> ResponseBuilder
[src]This method construct new ResponseBuilder
Trait Implementations
impl BodyEncoding for HttpResponseBuilder
[src]
impl BodyEncoding for HttpResponseBuilder
[src]fn get_encoding(&self) -> Option<ContentEncoding>
[src]
fn get_encoding(&self) -> Option<ContentEncoding>
[src]Get content encoding
fn encoding(&mut self, encoding: ContentEncoding) -> &mut Self
[src]
fn encoding(&mut self, encoding: ContentEncoding) -> &mut Self
[src]Set content encoding
impl Debug for ResponseBuilder
[src]
impl Debug for ResponseBuilder
[src]impl<'a> From<&'a ResponseHead> for ResponseBuilder
[src]
impl<'a> From<&'a ResponseHead> for ResponseBuilder
[src]Convert ResponseHead
to a ResponseBuilder
fn from(head: &'a ResponseHead) -> ResponseBuilder
[src]
fn from(head: &'a ResponseHead) -> ResponseBuilder
[src]Performs the conversion.
impl<B> From<Response<B>> for ResponseBuilder
[src]
impl<B> From<Response<B>> for ResponseBuilder
[src]Convert Response
to a ResponseBuilder
. Body get dropped.
fn from(res: Response<B>) -> ResponseBuilder
[src]
fn from(res: Response<B>) -> ResponseBuilder
[src]Performs the conversion.
impl From<ResponseBuilder> for Response
[src]
impl From<ResponseBuilder> for Response
[src]fn from(builder: ResponseBuilder) -> Self
[src]
fn from(builder: ResponseBuilder) -> Self
[src]Performs the conversion.
impl<Err: ErrorRenderer> Responder<Err> for ResponseBuilder
[src]
impl<Err: ErrorRenderer> Responder<Err> for ResponseBuilder
[src]fn respond_to(self, _: &HttpRequest) -> Self::Future
[src]
fn respond_to(self, _: &HttpRequest) -> Self::Future
[src]Convert itself to AsyncResult
or Error
.
fn with_status(self, status: StatusCode) -> CustomResponder<Self, Err> where
Self: Sized,
[src]
fn with_status(self, status: StatusCode) -> CustomResponder<Self, Err> where
Self: Sized,
[src]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>,
[src]
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>,
[src]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
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> Instrument for T
[src]
impl<T> Instrument for T
[src]fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
fn in_current_span(self) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self