[−][src]Struct actix_web::client::ClientRequest
An HTTP Client request builder
This type can be used to construct an instance of ClientRequest through a
builder-like pattern.
use futures::future::{Future, lazy}; use actix_rt::System; fn main() { System::new("test").block_on(lazy(|| { awc::Client::new() .get("http://www.rust-lang.org") // <- Create request builder .header("User-Agent", "Actix-web") .send() // <- Send http request .map_err(|_| ()) .and_then(|response| { // <- server http response println!("Response: {:?}", response); Ok(()) }) })); }
Methods
impl ClientRequest[src]
pub fn uri<U>(self, uri: U) -> ClientRequest where
Uri: HttpTryFrom<U>, [src]
Uri: HttpTryFrom<U>,
Set HTTP URI of request.
pub fn get_uri(&self) -> &Uri[src]
Get HTTP URI of request.
pub fn address(self, addr: SocketAddr) -> ClientRequest[src]
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[src]
Set HTTP method of this request.
pub fn get_method(&self) -> &Method[src]
Get HTTP method of this request
pub fn get_version(&self) -> &Version[src]
Get HTTP version of this request.
pub fn get_peer_addr(&self) -> &Option<SocketAddr>[src]
Get peer address of this request.
pub fn headers(&self) -> &HeaderMap[src]
Returns request's headers.
pub fn headers_mut(&mut self) -> &mut HeaderMap[src]
Returns request's mutable headers.
pub fn set<H>(self, hdr: H) -> ClientRequest where
H: Header, [src]
H: Header,
Set a header.
fn main() { let req = awc::Client::new() .get("http://www.rust-lang.org") .set(awc::http::header::Date::now()) .set(awc::http::header::ContentType(mime::TEXT_HTML)); }
pub fn header<K, V>(self, key: K, value: V) -> ClientRequest where
V: IntoHeaderValue,
HeaderName: HttpTryFrom<K>, [src]
V: IntoHeaderValue,
HeaderName: HttpTryFrom<K>,
Append a header.
Header gets appended to existing header.
To override header use set_header() method.
use awc::{http, Client}; fn main() { let req = Client::new() .get("http://www.rust-lang.org") .header("X-TEST", "value") .header(http::header::CONTENT_TYPE, "application/json"); }
pub fn set_header<K, V>(self, key: K, value: V) -> ClientRequest where
V: IntoHeaderValue,
HeaderName: HttpTryFrom<K>, [src]
V: IntoHeaderValue,
HeaderName: HttpTryFrom<K>,
Insert a header, replaces existing header.
pub fn set_header_if_none<K, V>(self, key: K, value: V) -> ClientRequest where
V: IntoHeaderValue,
HeaderName: HttpTryFrom<K>, [src]
V: IntoHeaderValue,
HeaderName: HttpTryFrom<K>,
Insert a header only if it is not yet set.
pub fn camel_case(self) -> ClientRequest[src]
Send headers in Camel-Case form.
pub fn force_close(self) -> ClientRequest[src]
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 where
HeaderValue: HttpTryFrom<V>, [src]
HeaderValue: HttpTryFrom<V>,
Set request's content type
pub fn content_length(self, len: u64) -> ClientRequest[src]
Set content length
pub fn basic_auth<U>(self, username: U, password: Option<&str>) -> ClientRequest where
U: Display, [src]
U: Display,
Set HTTP basic authorization header
pub fn bearer_auth<T>(self, token: T) -> ClientRequest where
T: Display, [src]
T: Display,
Set HTTP bearer authentication header
pub fn cookie(self, cookie: Cookie) -> ClientRequest[src]
Set a cookie
fn main() { System::new("test").block_on(lazy(|| { awc::Client::new().get("https://www.rust-lang.org") .cookie( awc::http::Cookie::build("name", "value") .domain("www.rust-lang.org") .path("/") .secure(true) .http_only(true) .finish(), ) .send() .map_err(|_| ()) .and_then(|response| { println!("Response: {:?}", response); Ok(()) }) })); }
pub fn no_decompress(self) -> ClientRequest[src]
Disable automatic decompress of response's body
pub fn timeout(self, timeout: Duration) -> ClientRequest[src]
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 if_true<F>(self, value: bool, f: F) -> ClientRequest where
F: FnOnce(ClientRequest) -> ClientRequest, [src]
F: FnOnce(ClientRequest) -> ClientRequest,
This method calls provided closure with builder reference if
value is true.
pub fn if_some<T, F>(self, value: Option<T>, f: F) -> ClientRequest where
F: FnOnce(T, ClientRequest) -> ClientRequest, [src]
F: FnOnce(T, ClientRequest) -> ClientRequest,
This method calls provided closure with builder reference if
value is Some.
pub fn freeze(self) -> Result<FrozenClientRequest, FreezeRequestError>[src]
Freeze request builder and construct FrozenClientRequest,
which could be used for sending same request multiple times.
pub fn send_body<B>(self, body: B) -> SendClientRequest where
B: Into<Body>, [src]
B: Into<Body>,
Complete request construction and send body.
pub fn send_json<T>(self, value: &T) -> SendClientRequest where
T: Serialize, [src]
T: Serialize,
Set a JSON body and generate ClientRequest
pub fn send_form<T>(self, value: &T) -> SendClientRequest where
T: Serialize, [src]
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 where
E: Into<Error> + 'static,
S: Stream<Item = Bytes, Error = E> + 'static, [src]
E: Into<Error> + 'static,
S: Stream<Item = Bytes, Error = E> + 'static,
Set an streaming body and generate ClientRequest.
pub fn send(self) -> SendClientRequest[src]
Set an empty body and generate ClientRequest.
Trait Implementations
Auto Trait Implementations
impl !Send for ClientRequest
impl Unpin for ClientRequest
impl !Sync for ClientRequest
impl !UnwindSafe for ClientRequest
impl !RefUnwindSafe for ClientRequest
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> From<T> for T[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Erased for T
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,