Skip to content

Commit

Permalink
deps, use upstream http-gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
blind-oracle committed Jun 14, 2024
1 parent b1cf631 commit f5661c9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 57 deletions.
23 changes: 13 additions & 10 deletions Cargo.lock

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

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 6 additions & 15 deletions src/routing/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use axum::{
extract::{Request, State},
response::Response,
response::{IntoResponse, Response},
Extension,
};
use bytes::Bytes;
Expand All @@ -13,7 +13,6 @@ use ic_http_gateway::{CanisterRequest, HttpGatewayClient, HttpGatewayRequestArgs
use super::{
error_cause::ErrorCause,
ic::{
convert_response,
transport::{PassHeaders, PASS_HEADERS},
IcResponseStatus,
},
Expand Down Expand Up @@ -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)
}
46 changes: 17 additions & 29 deletions src/routing/ic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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<HttpGatewayResponseBody>) -> Response {
let (parts, body) = resp.into_parts();
// pub fn convert_response(resp: Response<HttpGatewayResponseBody>) -> 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,
Expand Down

0 comments on commit f5661c9

Please sign in to comment.