Struct actix_web::client::ClientRequestBuilder
source · pub struct ClientRequestBuilder { /* private fields */ }
Expand description
An HTTP Client request builder
This type can be used to construct an instance of ClientRequest
through a
builder-like pattern.
Implementations
sourceimpl ClientRequestBuilder
impl ClientRequestBuilder
sourcepub fn get_method(&mut self) -> &Method
pub fn get_method(&mut self) -> &Method
Set HTTP method of this request.
sourcepub fn version(&mut self, version: Version) -> &mut Self
pub fn version(&mut self, version: Version) -> &mut Self
Set HTTP version of this request.
By default requests’s HTTP version depends on network stream
sourcepub fn header<K, V>(&mut self, key: K, value: V) -> &mut Selfwhere
HeaderName: HttpTryFrom<K>,
V: IntoHeaderValue,
pub fn header<K, V>(&mut self, key: K, value: V) -> &mut Selfwhere
HeaderName: HttpTryFrom<K>,
V: IntoHeaderValue,
Append a header.
Header gets appended to existing header.
To override header use set_header()
method.
use http::header;
fn main() {
let req = ClientRequest::build()
.header("X-TEST", "value")
.header(header::CONTENT_TYPE, "application/json")
.finish()
.unwrap();
}
sourcepub fn set_header<K, V>(&mut self, key: K, value: V) -> &mut Selfwhere
HeaderName: HttpTryFrom<K>,
V: IntoHeaderValue,
pub fn set_header<K, V>(&mut self, key: K, value: V) -> &mut Selfwhere
HeaderName: HttpTryFrom<K>,
V: IntoHeaderValue,
Set a header.
sourcepub fn set_header_if_none<K, V>(&mut self, key: K, value: V) -> &mut Selfwhere
HeaderName: HttpTryFrom<K>,
V: IntoHeaderValue,
pub fn set_header_if_none<K, V>(&mut self, key: K, value: V) -> &mut Selfwhere
HeaderName: HttpTryFrom<K>,
V: IntoHeaderValue,
Set a header only if it is not yet set.
sourcepub fn content_encoding(&mut self, enc: ContentEncoding) -> &mut Self
pub fn content_encoding(&mut self, enc: ContentEncoding) -> &mut Self
Set content encoding.
By default ContentEncoding::Identity
is used.
sourcepub fn content_type<V>(&mut self, value: V) -> &mut Selfwhere
HeaderValue: HttpTryFrom<V>,
pub fn content_type<V>(&mut self, value: V) -> &mut Selfwhere
HeaderValue: HttpTryFrom<V>,
Set request’s content type
sourcepub fn content_length(&mut self, len: u64) -> &mut Self
pub fn content_length(&mut self, len: u64) -> &mut Self
Set content length
Set a cookie
use actix_web::{client, http};
fn main() {
let req = client::ClientRequest::build()
.cookie(
http::Cookie::build("name", "value")
.domain("www.rust-lang.org")
.path("/")
.secure(true)
.http_only(true)
.finish(),
)
.finish()
.unwrap();
}
sourcepub fn no_default_headers(&mut self) -> &mut Self
pub fn no_default_headers(&mut self) -> &mut Self
Do not add default request headers.
By default Accept-Encoding
and User-Agent
headers are set.
sourcepub fn disable_decompress(&mut self) -> &mut Self
pub fn disable_decompress(&mut self) -> &mut Self
Disable automatic decompress response body
sourcepub fn write_buffer_capacity(&mut self, cap: usize) -> &mut Self
pub fn write_buffer_capacity(&mut self, cap: usize) -> &mut Self
Set write buffer capacity
Default buffer capacity is 32kb
sourcepub fn timeout(&mut self, timeout: Duration) -> &mut Self
pub fn timeout(&mut self, timeout: Duration) -> &mut Self
Set request timeout
Request timeout is a total time before response should be received. Default value is 5 seconds.
sourcepub fn with_connector(&mut self, conn: Addr<ClientConnector>) -> &mut Self
pub fn with_connector(&mut self, conn: Addr<ClientConnector>) -> &mut Self
Send request using custom connector
sourcepub fn with_connection(&mut self, conn: Connection) -> &mut Self
pub fn with_connection(&mut self, conn: Connection) -> &mut Self
Send request using existing Connection
sourcepub fn if_true<F>(&mut self, value: bool, f: F) -> &mut Selfwhere
F: FnOnce(&mut ClientRequestBuilder),
pub fn if_true<F>(&mut self, value: bool, f: F) -> &mut Selfwhere
F: FnOnce(&mut ClientRequestBuilder),
This method calls provided closure with builder reference if
value is true
.
sourcepub fn if_some<T, F>(&mut self, value: Option<T>, f: F) -> &mut Selfwhere
F: FnOnce(T, &mut ClientRequestBuilder),
pub fn if_some<T, F>(&mut self, value: Option<T>, f: F) -> &mut Selfwhere
F: FnOnce(T, &mut ClientRequestBuilder),
This method calls provided closure with builder reference if
value is Some
.
sourcepub fn body<B: Into<Body>>(&mut self, body: B) -> Result<ClientRequest, Error>
pub fn body<B: Into<Body>>(&mut self, body: B) -> Result<ClientRequest, Error>
Set a body and generate ClientRequest
.
ClientRequestBuilder
can not be used after this call.
sourcepub fn json<T: Serialize>(&mut self, value: T) -> Result<ClientRequest, Error>
pub fn json<T: Serialize>(&mut self, value: T) -> Result<ClientRequest, Error>
Set a JSON body and generate ClientRequest
ClientRequestBuilder
can not be used after this call.
sourcepub fn form<T: Serialize>(&mut self, value: T) -> Result<ClientRequest, Error>
pub fn form<T: Serialize>(&mut self, value: T) -> Result<ClientRequest, Error>
Set a urlencoded body and generate ClientRequest
ClientRequestBuilder
can not be used after this call.
sourcepub fn streaming<S, E>(&mut self, stream: S) -> Result<ClientRequest, Error>where
S: Stream<Item = Bytes, Error = E> + 'static,
E: Into<Error>,
pub fn streaming<S, E>(&mut self, stream: S) -> Result<ClientRequest, Error>where
S: Stream<Item = Bytes, Error = E> + 'static,
E: Into<Error>,
Set a streaming body and generate ClientRequest
.
ClientRequestBuilder
can not be used after this call.
sourcepub fn finish(&mut self) -> Result<ClientRequest, Error>
pub fn finish(&mut self) -> Result<ClientRequest, Error>
Set an empty body and generate ClientRequest
ClientRequestBuilder
can not be used after this call.
sourcepub fn take(&mut self) -> ClientRequestBuilder
pub fn take(&mut self) -> ClientRequestBuilder
This method construct new ClientRequestBuilder
Trait Implementations
sourceimpl Debug for ClientRequestBuilder
impl Debug for ClientRequestBuilder
sourceimpl<'a, S: 'static> From<&'a HttpRequest<S>> for ClientRequestBuilder
impl<'a, S: 'static> From<&'a HttpRequest<S>> for ClientRequestBuilder
Create ClientRequestBuilder
from HttpRequest
It is useful for proxy requests. This implementation copies all request headers and the method.