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]
impl HttpResponseBuilder
ⓘImportant traits for &'a mut Rpub 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.
ⓘImportant traits for &'a mut Rpub 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.
ⓘImportant traits for &'a mut Rpub 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() {}
ⓘImportant traits for &'a mut Rpub 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.
ⓘImportant traits for &'a mut Rpub 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.
ⓘImportant traits for &'a mut Rpub 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
ⓘImportant traits for &'a mut Rpub fn chunked(&mut self) -> &mut Self
[src]
pub fn chunked(&mut self) -> &mut Self
Enables automatic chunked transfer encoding
ⓘImportant traits for &'a mut Rpub fn no_chunking(&mut self) -> &mut Self
[src]
pub fn no_chunking(&mut self) -> &mut Self
Force disable chunked encoding
ⓘImportant traits for &'a mut Rpub 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
ⓘImportant traits for &'a mut Rpub fn content_length(&mut self, len: u64) -> &mut Self
[src]
pub fn content_length(&mut self, len: u64) -> &mut Self
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() }
ⓘImportant traits for &'a mut R
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 Rpub 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.
ⓘImportant traits for &'a mut Rpub 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.
ⓘImportant traits for &'a mut Rpub 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 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 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 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<'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