diff --git a/Cargo.lock b/Cargo.lock index 866d4d4..853c8be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1348,7 +1348,7 @@ dependencies = [ [[package]] name = "discower_bowndary" version = "0.1.0" -source = "git+https://github.com/dfinity/ic.git#3a2b891b34d92c03a1ba8e4a6bb73f702fb3f3d6" +source = "git+https://github.com/dfinity/ic.git#a05f9cd8749c8007c0626bdda5fe03869f260f81" dependencies = [ "arc-swap", "async-trait", @@ -2299,7 +2299,7 @@ dependencies = [ [[package]] name = "ic-cbor" version = "2.5.0" -source = "git+https://github.com/dfinity/response-verification#8d559e5a3652098796e5f153987fe5af74e3212b" +source = "git+https://github.com/dfinity/response-verification#35b21602b805ac27d247781a16fb674aaca4e603" dependencies = [ "candid", "ic-certification 2.5.0 (git+https://github.com/dfinity/response-verification)", @@ -2311,7 +2311,7 @@ dependencies = [ [[package]] name = "ic-certificate-verification" version = "2.5.0" -source = "git+https://github.com/dfinity/response-verification#8d559e5a3652098796e5f153987fe5af74e3212b" +source = "git+https://github.com/dfinity/response-verification#35b21602b805ac27d247781a16fb674aaca4e603" dependencies = [ "cached 0.47.0", "candid", @@ -2341,7 +2341,7 @@ dependencies = [ [[package]] name = "ic-certification" version = "2.5.0" -source = "git+https://github.com/dfinity/response-verification#8d559e5a3652098796e5f153987fe5af74e3212b" +source = "git+https://github.com/dfinity/response-verification#35b21602b805ac27d247781a16fb674aaca4e603" dependencies = [ "hex", "sha2 0.10.8", @@ -2446,7 +2446,7 @@ dependencies = [ [[package]] name = "ic-http-certification" version = "2.5.0" -source = "git+https://github.com/dfinity/response-verification#8d559e5a3652098796e5f153987fe5af74e3212b" +source = "git+https://github.com/dfinity/response-verification#35b21602b805ac27d247781a16fb674aaca4e603" dependencies = [ "candid", "http 0.2.12", @@ -2460,11 +2460,14 @@ dependencies = [ [[package]] name = "ic-http-gateway" version = "0.0.0" -source = "git+https://github.com/blind-oracle/http-gateway#bf8de646f4278c3958a0b247f19e4f9b9269b29b" +source = "git+https://github.com/dfinity/http-gateway#5977c9422e9c7e976cff5b14ba258db52e169b06" dependencies = [ + "bytes", "candid", "futures", "http 1.1.0", + "http-body 1.0.0", + "http-body-util", "ic-agent", "ic-http-certification", "ic-response-verification", @@ -2475,7 +2478,7 @@ dependencies = [ [[package]] name = "ic-representation-independent-hash" version = "2.5.0" -source = "git+https://github.com/dfinity/response-verification#8d559e5a3652098796e5f153987fe5af74e3212b" +source = "git+https://github.com/dfinity/response-verification#35b21602b805ac27d247781a16fb674aaca4e603" dependencies = [ "leb128", "sha2 0.10.8", @@ -2484,7 +2487,7 @@ dependencies = [ [[package]] name = "ic-response-verification" version = "2.5.0" -source = "git+https://github.com/dfinity/response-verification#8d559e5a3652098796e5f153987fe5af74e3212b" +source = "git+https://github.com/dfinity/response-verification#35b21602b805ac27d247781a16fb674aaca4e603" dependencies = [ "base64 0.21.7", "candid", @@ -3897,9 +3900,9 @@ checksum = "08ad765b21a08b1a8e5cdce052719188a23772bcbefb3c439f0baaf62c56ceac" [[package]] name = "redox_syscall" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" dependencies = [ "bitflags 2.5.0", ] diff --git a/Cargo.toml b/Cargo.toml index 865901f..8b8244a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,9 +58,7 @@ humantime = "2.1" hyper = "1.3" hyper-util = "0.1" ic-agent = { version = "0.35", features = ["reqwest"] } -#ic-http-gateway = { git = "https://github.com/dfinity/http-gateway" } -ic-http-gateway = { git = "https://github.com/blind-oracle/http-gateway" } -#ic-http-gateway = { path = "../http-gateway/packages/ic-http-gateway" } +ic-http-gateway = { git = "https://github.com/dfinity/http-gateway" } ic-transport-types = "0.35" instant-acme = "0.4" jemallocator = "0.5" diff --git a/src/routing/handler.rs b/src/routing/handler.rs index 6c55471..b6fe031 100644 --- a/src/routing/handler.rs +++ b/src/routing/handler.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use axum::{ extract::{Request, State}, - response::Response, + response::{IntoResponse, Response}, Extension, }; use bytes::Bytes; @@ -13,7 +13,6 @@ use ic_http_gateway::{CanisterRequest, HttpGatewayClient, HttpGatewayRequestArgs use super::{ error_cause::ErrorCause, ic::{ - convert_response, transport::{PassHeaders, PASS_HEADERS}, IcResponseStatus, }, @@ -78,24 +77,16 @@ pub async fn handler( }); // Execute the request - let req = state.client.request(args); - let req = if !ctx.verify { - req.unsafe_allow_skip_verification() - } else { - req - }; - + let mut req = state.client.request(args); + req.unsafe_set_allow_skip_verification(!ctx.verify); req.send().await }) - .await - .map_err(ErrorCause::from_err)?; + .await; let ic_status = IcResponseStatus::from(&resp); - let mut response = convert_response(resp.canister_response); - - response.extensions_mut().insert(ic_status); // Convert it into Axum response - //Ok(resp.canister_response.into_response()) + let mut response = resp.canister_response.into_response(); + response.extensions_mut().insert(ic_status); Ok(response) } diff --git a/src/routing/ic/mod.rs b/src/routing/ic/mod.rs index 723d9f7..ad16746 100644 --- a/src/routing/ic/mod.rs +++ b/src/routing/ic/mod.rs @@ -4,18 +4,9 @@ pub mod transport; use std::{fs, sync::Arc}; use anyhow::{Context, Error}; -use axum::{ - body::Body, - response::{IntoResponse, Response}, -}; -use bytes::Bytes; -use futures::StreamExt; -use http_body::Frame; -use http_body_util::{Full, StreamBody}; +use http_body_util::Either; use ic_agent::agent::http_transport::route_provider::RouteProvider; -use ic_http_gateway::{ - HttpGatewayClient, HttpGatewayResponse, HttpGatewayResponseBody, HttpGatewayResponseMetadata, -}; +use ic_http_gateway::{HttpGatewayClient, HttpGatewayResponse, HttpGatewayResponseMetadata}; use crate::{http::Client as HttpClient, Cli}; @@ -28,32 +19,29 @@ pub struct IcResponseStatus { impl From<&HttpGatewayResponse> for IcResponseStatus { fn from(value: &HttpGatewayResponse) -> Self { Self { - streaming: matches!( - value.canister_response.body(), - HttpGatewayResponseBody::Stream(_) - ), + streaming: matches!(value.canister_response.body(), Either::Left(_)), metadata: value.metadata.clone(), } } } -pub fn convert_response(resp: Response) -> Response { - let (parts, body) = resp.into_parts(); +// pub fn convert_response(resp: Response) -> Response { +// let (parts, body) = resp.into_parts(); - match body { - HttpGatewayResponseBody::Bytes(v) => { - Response::from_parts(parts, Body::new(Full::new(v.into()))).into_response() - } +// match body { +// HttpGatewayResponseBody::Bytes(v) => { +// Response::from_parts(parts, Body::new(Full::new(v.into()))).into_response() +// } - HttpGatewayResponseBody::Stream(v) => { - let v = v.map(|x| x.map(|y| Frame::data(Bytes::from(y)))); - let body = StreamBody::new(v); - let body = Body::new(body); +// HttpGatewayResponseBody::Stream(v) => { +// let v = v.map(|x| x.map(|y| Frame::data(Bytes::from(y)))); +// let body = StreamBody::new(v); +// let body = Body::new(body); - Response::from_parts(parts, body).into_response() - } - } -} +// Response::from_parts(parts, body).into_response() +// } +// } +// } pub fn setup( cli: &Cli,