[−][src]Struct actix_web::dev::HttpResponseBuilder
An HTTP response builder
This type can be used to construct an instance of HttpResponse
through a
builder-like pattern.
Methods
impl HttpResponseBuilder
[src]
impl HttpResponseBuilder
pub fn status(&mut self, status: StatusCode) -> &mut Self
[src]
pub fn status(&mut self, status: StatusCode) -> &mut Self
Set HTTP status code of this response.
pub fn version(&mut self, version: Version) -> &mut Self
[src]
pub fn version(&mut self, version: Version) -> &mut Self
Set HTTP version of this response.
By default response's http version depends on request's version.
pub fn header<K, V>(&mut self, key: K, value: V) -> &mut Self where
HeaderName: HttpTryFrom<K>,
V: IntoHeaderValue,
[src]
pub fn header<K, V>(&mut self, key: K, value: V) -> &mut Self where
HeaderName: HttpTryFrom<K>,
V: IntoHeaderValue,
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() {}
pub fn reason(&mut self, reason: &'static str) -> &mut Self
[src]
pub fn reason(&mut self, reason: &'static str) -> &mut Self
Set the custom reason for the response.
pub fn content_encoding(&mut self, enc: ContentEncoding) -> &mut Self
[src]
pub fn content_encoding(&mut self, enc: ContentEncoding) -> &mut Self
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.
pub fn force_close(&mut self) -> &mut Self
[src]
pub fn force_close(&mut self) -> &mut Self
Force close connection, even if it is marked as keep-alive
pub fn chunked(&mut self) -> &mut Self
[src]
pub fn chunked(&mut self) -> &mut Self
Enables automatic chunked transfer encoding
pub fn no_chunking(&mut self) -> &mut Self
[src]
pub fn no_chunking(&mut self) -> &mut Self
Force disable chunked encoding
pub fn content_type<V>(&mut self, value: V) -> &mut Self where
HeaderValue: HttpTryFrom<V>,
[src]
pub fn content_type<V>(&mut self, value: V) -> &mut Self where
HeaderValue: HttpTryFrom<V>,
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
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() }
pub fn if_true<F>(&mut self, value: bool, f: F) -> &mut Self where
F: FnOnce(&mut HttpResponseBuilder),
[src]
pub fn if_true<F>(&mut self, value: bool, f: F) -> &mut Self where
F: FnOnce(&mut HttpResponseBuilder),
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 HttpResponseBuilder),
[src]
pub fn if_some<T, F>(&mut self, value: Option<T>, f: F) -> &mut Self where
F: FnOnce(T, &mut HttpResponseBuilder),
This method calls provided closure with builder reference if value is Some.
pub fn write_buffer_capacity(&mut self, cap: usize) -> &mut Self
[src]
pub fn write_buffer_capacity(&mut self, cap: usize) -> &mut Self
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
pub fn body<B: Into<Body>>(&mut self, body: B) -> HttpResponse
[src]
pub fn body<B: Into<Body>>(&mut self, body: B) -> HttpResponse
Set a body and generate HttpResponse
.
HttpResponseBuilder
can not be used after this call.
pub fn streaming<S, E>(&mut self, stream: S) -> HttpResponse where
S: Stream<Item = Bytes, Error = E> + 'static,
E: Into<Error>,
[src]
pub fn streaming<S, E>(&mut self, stream: S) -> HttpResponse where
S: Stream<Item = Bytes, Error = E> + 'static,
E: Into<Error>,
Set a streaming body and generate HttpResponse
.
HttpResponseBuilder
can not be used after this call.
pub fn json<T: Serialize>(&mut self, value: T) -> HttpResponse
[src]
pub fn json<T: Serialize>(&mut self, value: T) -> HttpResponse
Set a json body and generate HttpResponse
HttpResponseBuilder
can not be used after this call.
pub fn json2<T: Serialize>(&mut self, value: &T) -> HttpResponse
[src]
pub fn json2<T: Serialize>(&mut self, value: &T) -> HttpResponse
Set a json body and generate HttpResponse
HttpResponseBuilder
can not be used after this call.
pub fn finish(&mut self) -> HttpResponse
[src]
pub fn finish(&mut self) -> HttpResponse
Set an empty body and generate HttpResponse
HttpResponseBuilder
can not be used after this call.
pub fn take(&mut self) -> HttpResponseBuilder
[src]
pub fn take(&mut self) -> HttpResponseBuilder
This method construct new HttpResponseBuilder
Trait Implementations
impl Responder for HttpResponseBuilder
[src]
impl Responder for HttpResponseBuilder
type Item = HttpResponse
The associated item which can be returned.
type Error = Error
The associated error which can be returned.
fn respond_to<S>(self, _: &HttpRequest<S>) -> Result<HttpResponse, Error>
[src]
fn respond_to<S>(self, _: &HttpRequest<S>) -> Result<HttpResponse, Error>
Convert itself to AsyncResult
or Error
.
impl From<HttpResponseBuilder> for HttpResponse
[src]
impl From<HttpResponseBuilder> for HttpResponse
fn from(builder: HttpResponseBuilder) -> Self
[src]
fn from(builder: HttpResponseBuilder) -> Self
Performs the conversion.
impl<'a> From<&'a ClientResponse> for HttpResponseBuilder
[src]
impl<'a> From<&'a ClientResponse> for HttpResponseBuilder
Create HttpResponseBuilder
from ClientResponse
It is useful for proxy response. This implementation copies all responses's headers and status.
fn from(resp: &'a ClientResponse) -> HttpResponseBuilder
[src]
fn from(resp: &'a ClientResponse) -> HttpResponseBuilder
Performs the conversion.
impl<'a, S> From<&'a HttpRequest<S>> for HttpResponseBuilder
[src]
impl<'a, S> From<&'a HttpRequest<S>> for HttpResponseBuilder
fn from(req: &'a HttpRequest<S>) -> HttpResponseBuilder
[src]
fn from(req: &'a HttpRequest<S>) -> HttpResponseBuilder
Performs the conversion.
Auto Trait Implementations
impl !Send for HttpResponseBuilder
impl !Send for HttpResponseBuilder
impl !Sync for HttpResponseBuilder
impl !Sync for HttpResponseBuilder
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 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
impl<T> Erased for T