diff --git a/Cargo.lock b/Cargo.lock index c63e9362..9973a44e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -148,6 +148,61 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "axum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1236b4b292f6c4d6dc34604bb5120d85c3fe1d1aa596bd5cc52ca054d13e7b9e" +dependencies = [ + "async-trait", + "axum-core", + "bytes", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.2.0", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "backoff" version = "0.4.0" @@ -1030,6 +1085,19 @@ dependencies = [ "http 1.0.0", ] +[[package]] +name = "http-body-util" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" +dependencies = [ + "bytes", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "pin-project-lite", +] + [[package]] name = "httparse" version = "1.8.0" @@ -1085,6 +1153,7 @@ dependencies = [ "http 1.0.0", "http-body 1.0.0", "httparse", + "httpdate", "itoa", "pin-project-lite", "smallvec", @@ -1150,6 +1219,7 @@ dependencies = [ name = "ic-agent" version = "0.33.0" dependencies = [ + "axum", "backoff", "cached", "candid", @@ -1159,8 +1229,10 @@ dependencies = [ "hex", "http 1.0.0", "http-body 1.0.0", + "http-body-util", "hyper 1.2.0", "hyper-rustls 0.26.0", + "hyper-util", "ic-certification", "ic-transport-types", "ic-verify-bls-signature", @@ -1520,6 +1592,12 @@ dependencies = [ "logos-codegen", ] +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + [[package]] name = "memchr" version = "2.5.0" @@ -2305,6 +2383,16 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_path_to_error" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4beec8bce849d58d06238cb50db2e1c417cfeafa4c63f692b15c82b7c80f8335" +dependencies = [ + "itoa", + "serde", +] + [[package]] name = "serde_repr" version = "0.1.16" @@ -2537,6 +2625,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + [[package]] name = "term" version = "0.7.0" diff --git a/ic-agent/Cargo.toml b/ic-agent/Cargo.toml index 4bed7356..ddf19962 100644 --- a/ic-agent/Cargo.toml +++ b/ic-agent/Cargo.toml @@ -15,6 +15,7 @@ keywords = ["internet-computer", "agent", "icp", "dfinity"] include = ["src", "Cargo.toml", "../LICENSE", "README.md"] [dependencies] +axum = "^0.7.4" backoff = "0.4.0" cached = { version = "0.46", features = ["ahash"], default-features = false } candid = { workspace = true } @@ -23,6 +24,8 @@ futures-util = { workspace = true } hex = { workspace = true } http = "1.0.0" http-body = "1.0.0" +http-body-util = "0.1.0" +hyper-util = { version = "0.1.3", features = ["client", "client-legacy", "http2"] } ic-certification = { workspace = true } ic-transport-types = { workspace = true } ic-verify-bls-signature = "0.1" diff --git a/ic-agent/src/agent/http_transport/hyper_transport.rs b/ic-agent/src/agent/http_transport/hyper_transport.rs index c5b1f5ce..80aad6ac 100644 --- a/ic-agent/src/agent/http_transport/hyper_transport.rs +++ b/ic-agent/src/agent/http_transport/hyper_transport.rs @@ -3,12 +3,13 @@ pub use hyper; use std::{any, error::Error, future::Future, marker::PhantomData, sync::atomic::AtomicPtr}; -use http_body::{LengthLimitError, Limited}; -use hyper::{ - body::HttpBody, client::HttpConnector, header::CONTENT_TYPE, service::Service, Client, Method, - Request, Response, -}; +//use http_body::{LengthLimitError, Limited}; +use axum::body::HttpBody; +use hyper::{header::CONTENT_TYPE, service::Service, Method, Request, Response}; use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder}; +use hyper_util::client::legacy::connect::HttpConnector; +use hyper_util::client::legacy::Client; +use hyper_util::rt::TokioExecutor; use crate::{ agent::{ @@ -91,7 +92,7 @@ impl HyperTransport { .enable_http1() .enable_http2() .build(); - Self::create_with_service(url, Client::builder().build(connector)) + Self::create_with_service(url, Client::builder(TokioExecutor::new()).build(connector)) } } @@ -166,21 +167,21 @@ where .map_err(map_error)?; let (parts, body) = response.into_parts(); - let body = if let Some(limit) = self.max_response_body_size { - hyper::body::to_bytes(Limited::new(body, limit)) - .await - .map_err(|err| { - if err.downcast_ref::().is_some() { - AgentError::ResponseSizeExceededLimit() - } else { - AgentError::TransportError(err) - } - })? - } else { - hyper::body::to_bytes(body) - .await - .map_err(|err| AgentError::TransportError(Box::new(err)))? - }; + let body: hyper::body::Bytes = todo!(""); /*if let Some(limit) = self.max_response_body_size { + hyper::body::to_bytes(Limited::new(body, limit)) + .await + .map_err(|err| { + if err.downcast_ref::().is_some() { + AgentError::ResponseSizeExceededLimit() + } else { + AgentError::TransportError(err) + } + })? + } else { + hyper::body::to_bytes(body) + .await + .map_err(|err| AgentError::TransportError(Box::new(err)))? + };*/ let (status, headers, body) = (parts.status, parts.headers, body.to_vec()); if status.is_client_error() || status.is_server_error() { @@ -261,6 +262,7 @@ where } } +/* #[cfg(test)] mod test { use super::HyperTransport; @@ -299,3 +301,4 @@ mod test { test("https://fooic0.app.ic0.app", "https://ic0.app/api/v2/"); } } +*/