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]
ⓘImportant traits for &'a mut Wpub fn status(&mut self, status: StatusCode) -> &mut Self
[src]
Set HTTP status code of this response.
ⓘImportant traits for &'a mut Wpub fn version(&mut self, version: Version) -> &mut Self
[src]
Set HTTP version of this response.
By default response's http version depends on request's version.
ⓘImportant traits for &'a mut Wpub fn header<K, V>(&mut self, key: K, value: V) -> &mut Self where
HeaderName: HttpTryFrom<K>,
V: IntoHeaderValue,
[src]
HeaderName: HttpTryFrom<K>,
V: IntoHeaderValue,
Set a header.
use http::header; fn index(req: HttpRequest) -> Result<HttpResponse> { Ok(HttpOk.build() .header("X-TEST", "value") .header(header::CONTENT_TYPE, "application/json") .finish()?) } fn main() {}
ⓘImportant traits for &'a mut Wpub fn reason(&mut self, reason: &'static str) -> &mut Self
[src]
Set the custom reason for the response.
ⓘImportant traits for &'a mut Wpub fn content_encoding(&mut self, enc: ContentEncoding) -> &mut Self
[src]
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 Wpub fn force_close(&mut self) -> &mut Self
[src]
Force close connection, even if it is marked as keep-alive
ⓘImportant traits for &'a mut Wpub fn chunked(&mut self) -> &mut Self
[src]
Enables automatic chunked transfer encoding
ⓘImportant traits for &'a mut Wpub fn no_chunking(&mut self) -> &mut Self
[src]
Force disable chunked encoding
ⓘImportant traits for &'a mut Wpub fn content_type<V>(&mut self, value: V) -> &mut Self where
HeaderValue: HttpTryFrom<V>,
[src]
HeaderValue: HttpTryFrom<V>,
Set response content type
ⓘImportant traits for &'a mut Wpub fn content_length(&mut self, len: u64) -> &mut Self
[src]
Set content length
ⓘImportant traits for &'a mut W[src]
Set a cookie
use actix_web::headers::Cookie; fn index(req: HttpRequest) -> Result<HttpResponse> { Ok(HttpOk.build() .cookie( Cookie::build("name", "value") .domain("www.rust-lang.org") .path("/") .secure(true) .http_only(true) .finish()) .finish()?) } fn main() {}
ⓘImportant traits for &'a mut W[src]
Remove cookie, cookie has to be cookie from HttpRequest::cookies()
method.
ⓘImportant traits for &'a mut Wpub fn if_true<F>(&mut self, value: bool, f: F) -> &mut Self where
F: FnOnce(&mut HttpResponseBuilder),
[src]
F: FnOnce(&mut HttpResponseBuilder),
This method calls provided closure with builder reference if value is true.
ⓘImportant traits for &'a mut Wpub fn if_some<T, F>(&mut self, value: Option<T>, f: F) -> &mut Self where
F: FnOnce(T, &mut HttpResponseBuilder),
[src]
F: FnOnce(T, &mut HttpResponseBuilder),
This method calls provided closure with builder reference if value is Some.
ⓘImportant traits for &'a mut Wpub fn write_buffer_capacity(&mut self, cap: usize) -> &mut Self
[src]
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
) -> Result<HttpResponse, HttpError>
[src]
&mut self,
body: B
) -> Result<HttpResponse, HttpError>
Set a body and generate HttpResponse
.
HttpResponseBuilder
can not be used after this call.
pub fn streaming<S>(&mut self, stream: S) -> Result<HttpResponse, HttpError> where
S: Stream<Item = Bytes, Error = Error> + 'static,
[src]
S: Stream<Item = Bytes, Error = Error> + 'static,
Set a streaming body and generate HttpResponse
.
HttpResponseBuilder
can not be used after this call.
pub fn json<T: Serialize>(&mut self, value: T) -> Result<HttpResponse, Error>
[src]
Set a json body and generate HttpResponse
HttpResponseBuilder
can not be used after this call.
pub fn finish(&mut self) -> Result<HttpResponse, HttpError>
[src]
Set an empty body and generate HttpResponse
HttpResponseBuilder
can not be used after this call.
pub fn take(&mut self) -> HttpResponseBuilder
[src]
This method construct new HttpResponseBuilder
Trait Implementations
impl From<HttpResponseBuilder> for HttpResponse
[src]
fn from(builder: HttpResponseBuilder) -> Self
[src]
Performs the conversion.
impl Responder for HttpResponseBuilder
[src]
type Item = HttpResponse
The associated item which can be returned.
type Error = HttpError
The associated error which can be returned.
fn respond_to(self, _: HttpRequest) -> Result<HttpResponse, HttpError>
[src]
Convert itself to Reply
or Error
.