mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-25 06:39:22 +02:00
use tokio::main in client example
This commit is contained in:
@ -109,6 +109,7 @@ futures-util = { version = "0.3.7", default-features = false }
|
||||
static_assertions = "1.1"
|
||||
rcgen = "0.8"
|
||||
rustls-pemfile = "0.2"
|
||||
tokio = { version = "1.13.1", features = ["rt-multi-thread", "macros"] }
|
||||
zstd = "0.9"
|
||||
|
||||
[[example]]
|
||||
|
@ -1,13 +1,13 @@
|
||||
use std::error::Error as StdError;
|
||||
|
||||
#[actix_web::main]
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn StdError>> {
|
||||
std::env::set_var("RUST_LOG", "client=trace,awc=trace,actix_http=trace");
|
||||
env_logger::init();
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
|
||||
// construct request builder
|
||||
let client = awc::Client::new();
|
||||
|
||||
// Create request builder, configure request and send
|
||||
// configure request
|
||||
let request = client
|
||||
.get("https://www.rust-lang.org/")
|
||||
.append_header(("User-Agent", "Actix-web"));
|
||||
@ -16,7 +16,7 @@ async fn main() -> Result<(), Box<dyn StdError>> {
|
||||
|
||||
let mut response = request.send().await?;
|
||||
|
||||
// server http response
|
||||
// server response head
|
||||
println!("Response: {:?}", response);
|
||||
|
||||
// read response body
|
||||
|
@ -207,7 +207,7 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
/// Maximum supported HTTP major version.
|
||||
/// Sets maximum supported HTTP major version.
|
||||
///
|
||||
/// Supported versions are HTTP/1.1 and HTTP/2.
|
||||
pub fn max_http_version(mut self, val: http::Version) -> Self {
|
||||
@ -222,8 +222,8 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
/// Indicates the initial window size (in octets) for
|
||||
/// HTTP2 stream-level flow control for received data.
|
||||
/// Sets the initial window size (in octets) for HTTP/2 stream-level flow control for
|
||||
/// received data.
|
||||
///
|
||||
/// The default value is 65,535 and is good for APIs, but not for big objects.
|
||||
pub fn initial_window_size(mut self, size: u32) -> Self {
|
||||
@ -231,8 +231,8 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
/// Indicates the initial window size (in octets) for
|
||||
/// HTTP2 connection-level flow control for received data.
|
||||
/// Sets the initial window size (in octets) for HTTP/2 connection-level flow control for
|
||||
/// received data.
|
||||
///
|
||||
/// The default value is 65,535 and is good for APIs, but not for big objects.
|
||||
pub fn initial_connection_window_size(mut self, size: u32) -> Self {
|
||||
@ -243,6 +243,7 @@ where
|
||||
/// Set total number of simultaneous connections per type of scheme.
|
||||
///
|
||||
/// If limit is 0, the connector has no limit.
|
||||
///
|
||||
/// The default limit size is 100.
|
||||
pub fn limit(mut self, limit: usize) -> Self {
|
||||
self.config.limit = limit;
|
||||
|
@ -67,12 +67,13 @@ impl Default for Client {
|
||||
}
|
||||
|
||||
impl Client {
|
||||
/// Create new client instance with default settings.
|
||||
/// Constructs new client instance with default settings.
|
||||
pub fn new() -> Client {
|
||||
Client::default()
|
||||
}
|
||||
|
||||
/// Create `Client` builder.
|
||||
/// Constructs new `Client` builder.
|
||||
///
|
||||
/// This function is equivalent of `ClientBuilder::new()`.
|
||||
pub fn builder() -> ClientBuilder<
|
||||
impl Service<
|
||||
|
Reference in New Issue
Block a user