Struct awc::ClientRequest [−][src]
pub struct ClientRequest { /* fields omitted */ }
Expand description
An HTTP Client request builder
This type can be used to construct an instance of ClientRequest
through a
builder-like pattern.
#[actix_rt::main]
async fn main() {
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
Set HTTP URI of request.
Set socket address of the server.
This address is used for connection. If address is not provided url’s host name get resolved.
Get HTTP method of this request
Get HTTP version of this request.
Get peer address of this request.
Returns request’s mutable headers.
Insert a header, replacing any that were set with an equivalent field name.
Insert a header only if it is not yet set.
Append a header, keeping any that were set with an equivalent field name.
use awc::http::header::CONTENT_TYPE;
Client::new()
.get("http://www.rust-lang.org")
.insert_header(("X-TEST", "value"))
.insert_header((CONTENT_TYPE, mime::APPLICATION_JSON));
Send headers in Camel-Case
form.
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) -> Self where
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
pub fn content_type<V>(self, value: V) -> Self where
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
Set request’s content type
Set content length
Set HTTP basic authorization header.
If no password is needed, just provide an empty string.
Set HTTP bearer authentication header
Set a cookie
#[actix_rt::main]
async fn main() {
let resp = awc::Client::new().get("https://www.rust-lang.org")
.cookie(
awc::cookie::Cookie::build("name", "value")
.domain("www.rust-lang.org")
.path("/")
.secure(true)
.http_only(true)
.finish(),
)
.send()
.await;
println!("Response: {:?}", resp);
}
Disable automatic decompress of response’s body
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.
Sets the query part of the request
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ⓘNotable traits for SendClientRequestimpl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
where
B: Into<AnyBody>,
pub fn send_body<B>(self, body: B) -> SendClientRequestⓘNotable traits for SendClientRequestimpl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
where
B: Into<AnyBody>,
impl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
Complete request construction and send body.
pub fn send_json<T: Serialize>(self, value: &T) -> SendClientRequestⓘNotable traits for SendClientRequestimpl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
pub fn send_json<T: Serialize>(self, value: &T) -> SendClientRequestⓘNotable traits for SendClientRequestimpl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
impl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
Set a JSON body and generate ClientRequest
pub fn send_form<T: Serialize>(self, value: &T) -> SendClientRequestⓘNotable traits for SendClientRequestimpl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
pub fn send_form<T: Serialize>(self, value: &T) -> SendClientRequestⓘNotable traits for SendClientRequestimpl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
impl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
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ⓘNotable traits for SendClientRequestimpl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
where
S: Stream<Item = Result<Bytes, E>> + Unpin + 'static,
E: Into<Box<dyn Error>> + 'static,
pub fn send_stream<S, E>(self, stream: S) -> SendClientRequestⓘNotable traits for SendClientRequestimpl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
where
S: Stream<Item = Result<Bytes, E>> + Unpin + 'static,
E: Into<Box<dyn Error>> + 'static,
impl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
Set an streaming body and generate ClientRequest
.
pub fn send(self) -> SendClientRequestⓘNotable traits for SendClientRequestimpl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
pub fn send(self) -> SendClientRequestⓘNotable traits for SendClientRequestimpl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
impl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
Set an empty body and generate ClientRequest
.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for ClientRequest
impl !Send for ClientRequest
impl !Sync for ClientRequest
impl Unpin for ClientRequest
impl !UnwindSafe for ClientRequest
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more