Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mraszyk committed Mar 4, 2024
1 parent 552d11b commit aefb541
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 21 deletions.
94 changes: 94 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ic-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"
Expand Down
45 changes: 24 additions & 21 deletions ic-agent/src/agent/http_transport/hyper_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -91,7 +92,7 @@ impl<B1: HyperBody> HyperTransport<B1> {
.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))
}
}

Expand Down Expand Up @@ -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::<LengthLimitError>().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::<LengthLimitError>().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() {
Expand Down Expand Up @@ -261,6 +262,7 @@ where
}
}

/*
#[cfg(test)]
mod test {
use super::HyperTransport;
Expand Down Expand Up @@ -299,3 +301,4 @@ mod test {
test("https://fooic0.app.ic0.app", "https://ic0.app/api/v2/");
}
}
*/

0 comments on commit aefb541

Please sign in to comment.