Struct actix_test::ClientRequest
pub struct ClientRequest { /* 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.
let response = awc::Client::new()
.get("http://www.rust-lang.org") // <- Create request builder
.insert_header(("User-Agent", "Actix-web"))
.send() // <- Send HTTP request
.await;
response.and_then(|response| { // <- server HTTP response
println!("Response: {:?}", response);
Ok(())
});
Implementations§
§impl ClientRequest
impl ClientRequest
pub fn uri<U>(self, uri: U) -> ClientRequest
pub fn uri<U>(self, uri: U) -> ClientRequest
Set HTTP URI of request.
pub fn address(self, addr: SocketAddr) -> ClientRequest
pub fn address(self, addr: SocketAddr) -> ClientRequest
Set socket address of the server.
This address is used for connection. If address is not provided url’s host name get resolved.
pub fn method(self, method: Method) -> ClientRequest
pub fn method(self, method: Method) -> ClientRequest
Set HTTP method of this request.
pub fn get_method(&self) -> &Method
pub fn get_method(&self) -> &Method
Get HTTP method of this request
pub fn get_version(&self) -> &Version
pub fn get_version(&self) -> &Version
Get HTTP version of this request.
pub fn get_peer_addr(&self) -> &Option<SocketAddr>
pub fn get_peer_addr(&self) -> &Option<SocketAddr>
Get peer address of this request.
pub fn headers(&self) -> &HeaderMap
pub fn headers(&self) -> &HeaderMap
Returns request’s headers.
pub fn headers_mut(&mut self) -> &mut HeaderMap
pub fn headers_mut(&mut self) -> &mut HeaderMap
Returns request’s mutable headers.
pub fn insert_header(self, header: impl TryIntoHeaderPair) -> ClientRequest
pub fn insert_header(self, header: impl TryIntoHeaderPair) -> ClientRequest
Insert a header, replacing any that were set with an equivalent field name.
pub fn insert_header_if_none(
self,
header: impl TryIntoHeaderPair
) -> ClientRequest
pub fn insert_header_if_none( self, header: impl TryIntoHeaderPair ) -> ClientRequest
Insert a header only if it is not yet set.
pub fn append_header(self, header: impl TryIntoHeaderPair) -> ClientRequest
pub fn append_header(self, header: impl TryIntoHeaderPair) -> ClientRequest
Append a header, keeping any that were set with an equivalent field name.
use awc::{http::header, Client};
Client::new()
.get("http://www.rust-lang.org")
.insert_header(("X-TEST", "value"))
.insert_header((header::CONTENT_TYPE, mime::APPLICATION_JSON));
pub fn camel_case(self) -> ClientRequest
pub fn camel_case(self) -> ClientRequest
Send headers in Camel-Case
form.
pub fn force_close(self) -> ClientRequest
pub fn force_close(self) -> ClientRequest
Force close connection instead of returning it back to connections pool. This setting affect only HTTP/1 connections.
pub fn content_type<V>(self, value: V) -> ClientRequest
pub fn content_type<V>(self, value: V) -> ClientRequest
Set request’s content type
pub fn content_length(self, len: u64) -> ClientRequest
pub fn content_length(self, len: u64) -> ClientRequest
Set content length
pub fn basic_auth(
self,
username: impl Display,
password: impl Display
) -> ClientRequest
pub fn basic_auth( self, username: impl Display, password: impl Display ) -> ClientRequest
Set HTTP basic authorization header.
If no password is needed, just provide an empty string.
pub fn bearer_auth(self, token: impl Display) -> ClientRequest
pub fn bearer_auth(self, token: impl Display) -> ClientRequest
Set HTTP bearer authentication header
Available on crate feature cookies
only.
cookies
only.Set a cookie
use awc::{cookie::Cookie, Client};
let res = Client::new().get("https://httpbin.org/cookies")
.cookie(Cookie::new("name", "value"))
.send()
.await;
println!("Response: {:?}", res);
pub fn no_decompress(self) -> ClientRequest
pub fn no_decompress(self) -> ClientRequest
Disable automatic decompress of response’s body
pub fn timeout(self, timeout: Duration) -> ClientRequest
pub fn timeout(self, timeout: Duration) -> ClientRequest
Set request timeout. Overrides client wide timeout setting.
Request timeout is the total time before a response must be received. Default value is 5 seconds.
pub fn query<T>(self, query: &T) -> Result<ClientRequest, Error>where
T: Serialize,
pub fn query<T>(self, query: &T) -> Result<ClientRequest, Error>where
T: Serialize,
Sets the query part of the request
pub fn freeze(self) -> Result<FrozenClientRequest, FreezeRequestError>
pub fn freeze(self) -> Result<FrozenClientRequest, FreezeRequestError>
Freeze request builder and construct FrozenClientRequest
,
which could be used for sending same request multiple times.
pub fn send_body<B>(self, body: B) -> SendClientRequestwhere
B: MessageBody + 'static,
pub fn send_body<B>(self, body: B) -> SendClientRequestwhere
B: MessageBody + 'static,
Complete request construction and send body.
pub fn send_json<T>(self, value: &T) -> SendClientRequestwhere
T: Serialize,
pub fn send_json<T>(self, value: &T) -> SendClientRequestwhere
T: Serialize,
Set a JSON body and generate ClientRequest
pub fn send_form<T>(self, value: &T) -> SendClientRequestwhere
T: Serialize,
pub fn send_form<T>(self, value: &T) -> SendClientRequestwhere
T: Serialize,
Set a urlencoded body and generate ClientRequest
ClientRequestBuilder
can not be used after this call.
pub fn send_stream<S, E>(self, stream: S) -> SendClientRequest
pub fn send_stream<S, E>(self, stream: S) -> SendClientRequest
Set an streaming body and generate ClientRequest
.
pub fn send(self) -> SendClientRequest
pub fn send(self) -> SendClientRequest
Set an empty body and generate ClientRequest
.