Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit d378692

Browse files
committed
wip
1 parent 562a372 commit d378692

7 files changed

Lines changed: 57 additions & 36 deletions

File tree

Cargo.lock

Lines changed: 22 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ resolver = "2"
66
futures = "0.3.29"
77
serde = { version = "1.0.192", features = ["derive"] }
88
serde_json = "1.0.108"
9-
tokio = { version = "1.34.0", features = ["macros", "rt-multi-thread"] }
10-
hyper = { version = "0.14.27", features = ["http1", "http2", "client"] }
9+
tokio = { version = "1.34.0", default-features = false }
10+
hyper = { version = "0.14.27", default-features = false }
1111
tracing = "0.1.40"
12+
http = "0.2.11"
13+
http-body = "0.4.5"
14+
bytes = "1.5.0"

crates/common/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ path = "src/lib.rs"
88

99
[dependencies]
1010
tracing = { workspace = true }
11+
futures = { workspace = true }
12+
http = { workspace = true }
13+
http-body = { workspace = true }
14+
bytes = { workspace = true }

crates/common/src/http.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use bytes::Bytes as RawBytes;
2+
use futures::AsyncRead;
3+
use http::{HeaderMap, HeaderValue, Request, Response};
4+
5+
pub type HttpHeadersMap = HeaderMap<HeaderValue>;
6+
pub type HttpRequest = Request<impl AsyncRead>;
7+
pub type Bytes = RawBytes;
8+
pub type HttpResponse = Response<RawBytes>;
9+
10+
pub trait IntoResponse {
11+
fn into_response(self) -> HttpResponse;
12+
}

crates/common/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod http;

crates/conductor/Cargo.toml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22
name = "conductor"
33
version = "0.1.0"
44
edition = "2021"
5-
default-run = "conductor"
65

76
[[bin]]
87
name = "conductor"
98
path = "src/main.rs"
10-
bench = false
9+
10+
[lib]
11+
path = "src/lib.rs"
1112

1213
[dependencies]
1314
conductor_config = { path = "../config" }
1415
conductor_engine = { path = "../engine" }
1516
conductor_common = { path = "../common" }
1617
serde = { workspace = true }
1718
serde_json = { workspace = true }
18-
tokio = { workspace = true }
19-
hyper = { workspace = true }
19+
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
20+
hyper = { workspace = true, features = ["http1", "http2", "client"] }
2021
axum = { version = "0.6.20", features = ["headers"] }
2122
tracing = { workspace = true }
2223
tracing-subscriber = "0.3.18"
@@ -25,7 +26,7 @@ hyper-tls = "0.5.0"
2526
axum-macros = "0.3.8"
2627
tokio-util = { version = "0.7.10", features = ["io", "compat"] }
2728
tower-http = { version = "0.4.4", features = ["cors"] }
28-
http = "0.2.11"
29+
http = { workspace = true }
2930
mime = "0.3.17"
3031
url = "2.4.1"
3132
graphql-parser = "0.4.0"
@@ -35,6 +36,3 @@ openssl = { version = "0.10", features = ["vendored"] }
3536

3637
[dev-dependencies]
3738
httpmock = "0.6"
38-
39-
[lib]
40-
path = "src/lib.rs"

crates/conductor/src/plugins/flow_context.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
use axum::{body::BoxBody, response::IntoResponse};
2-
use http::{Request, Response};
1+
use conductor_common::http::{HttpRequest, HttpResponse, IntoResponse};
32
use serde::de::DeserializeOwned;
43
use serde_json::from_slice;
54

65
use crate::{
76
endpoint::endpoint_runtime::EndpointRuntime, graphql_utils::ParsedGraphQLRequest,
87
http_utils::ExtractGraphQLOperationError,
98
};
10-
use hyper::{body::to_bytes, Body};
9+
use hyper::body::to_bytes;
1110

1211
#[derive(Debug)]
1312
pub struct FlowContext<'a> {
1413
pub endpoint: Option<&'a EndpointRuntime>,
1514
pub downstream_graphql_request: Option<ParsedGraphQLRequest>,
16-
pub downstream_http_request: &'a mut Request<Body>,
17-
pub short_circuit_response: Option<Response<BoxBody>>,
15+
pub downstream_http_request: &'a mut HttpRequest,
16+
pub short_circuit_response: Option<HttpResponse>,
1817
pub downstream_request_body_bytes: Option<Result<tokio_util::bytes::Bytes, hyper::Error>>,
1918
}
2019

2120
impl<'a> FlowContext<'a> {
22-
pub fn new(endpoint: &'a EndpointRuntime, request: &'a mut Request<Body>) -> Self {
21+
pub fn new(endpoint: &'a EndpointRuntime, request: &'a mut HttpRequest) -> Self {
2322
FlowContext {
2423
downstream_graphql_request: None,
2524
downstream_http_request: request,
@@ -32,7 +31,7 @@ impl<'a> FlowContext<'a> {
3231
pub async fn consume_body(&mut self) -> &Result<tokio_util::bytes::Bytes, hyper::Error> {
3332
if self.downstream_request_body_bytes.is_none() {
3433
self.downstream_request_body_bytes =
35-
Some(to_bytes(self.downstream_http_request.body_mut()).await);
34+
Some(to_bytes(self.downstream_http_request.body_mut()));
3635
}
3736

3837
return self.downstream_request_body_bytes.as_ref().unwrap();
@@ -56,7 +55,7 @@ impl<'a> FlowContext<'a> {
5655
}
5756

5857
#[cfg(test)]
59-
pub fn empty_from_request(request: &'a mut Request<Body>) -> Self {
58+
pub fn empty_from_request(request: &'a mut HttpRequest) -> Self {
6059
FlowContext {
6160
downstream_graphql_request: None,
6261
downstream_http_request: request,

0 commit comments

Comments
 (0)