Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ alloy-transport-http = { version = "1.4.3", features = [
"hyper",
], optional = true }
url = { version = "2.5.7", optional = true }
hyper-tungstenite = "0.19.0"

[dev-dependencies]
tempfile = "3.23.0"
Expand Down
6 changes: 5 additions & 1 deletion src/attested_get.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! A one-shot attested TLS proxy client which sends a single GET request and returns the response
use crate::{AttestationGenerator, AttestationVerifier, ProxyClient, ProxyError};
use crate::{
http_version::HttpVersion, AttestationGenerator, AttestationVerifier, ProxyClient, ProxyError,
};
use tokio_rustls::rustls::pki_types::CertificateDer;

/// Start a proxy-client, send a single HTTP GET request to the given path and return the
Expand All @@ -17,6 +19,7 @@ pub async fn attested_get(
AttestationGenerator::with_no_attestation(),
attestation_verifier,
remote_certificate,
HttpVersion::Http2,
)
.await?;

Expand Down Expand Up @@ -103,6 +106,7 @@ mod tests {
AttestationGenerator::with_no_attestation(),
AttestationVerifier::mock(),
None,
HttpVersion::Http2,
)
.await
.unwrap();
Expand Down
3 changes: 2 additions & 1 deletion src/file_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub(crate) async fn static_file_server(path: PathBuf) -> Result<SocketAddr, Prox

#[cfg(test)]
mod tests {
use crate::{attestation::AttestationType, ProxyClient};
use crate::{attestation::AttestationType, http_version::HttpVersion, ProxyClient};

use super::*;
use crate::test_helpers::{generate_certificate_chain, generate_tls_config};
Expand Down Expand Up @@ -122,6 +122,7 @@ mod tests {
AttestationGenerator::with_no_attestation(),
AttestationVerifier::mock(),
None,
HttpVersion::Http2,
)
.await
.unwrap();
Expand Down
47 changes: 3 additions & 44 deletions src/http_version.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! HTTP Version support and negotiation
use hyper::Response;
use hyper_util::rt::TokioIo;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};

pub const ALPN_H2: &[u8] = b"h2";
pub const ALPN_HTTP11: &[u8] = b"http/1.1";
Expand Down Expand Up @@ -47,17 +46,6 @@ impl HttpVersion {
type Http1Sender = hyper::client::conn::http1::SendRequest<hyper::body::Incoming>;
type Http2Sender = hyper::client::conn::http2::SendRequest<hyper::body::Incoming>;

type Http1Connection = hyper::client::conn::http1::Connection<
TokioIo<tokio_rustls::client::TlsStream<tokio::net::TcpStream>>,
hyper::body::Incoming,
>;

type Http2Connection = hyper::client::conn::http2::Connection<
TokioIo<tokio_rustls::client::TlsStream<tokio::net::TcpStream>>,
hyper::body::Incoming,
crate::TokioExecutor,
>;

/// A protocol version agnostic HTTP sender
pub enum HttpSender {
Http1(Http1Sender),
Expand Down Expand Up @@ -88,34 +76,5 @@ impl HttpSender {
}
}

pin_project_lite::pin_project! {
/// A protocol version agnostic HTTP connection
#[project = HttpConnectionProj]
pub enum HttpConnection {
Http1 { #[pin] inner: Http1Connection },
Http2 { #[pin] inner: Http2Connection },
}
}

impl From<Http1Connection> for HttpConnection {
fn from(inner: Http1Connection) -> Self {
Self::Http1 { inner }
}
}

impl From<Http2Connection> for HttpConnection {
fn from(inner: Http2Connection) -> Self {
Self::Http2 { inner }
}
}

impl Future for HttpConnection {
type Output = Result<(), hyper::Error>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match self.project() {
HttpConnectionProj::Http1 { inner } => inner.poll(cx),
HttpConnectionProj::Http2 { inner } => inner.poll(cx),
}
}
}
/// A protocol version agnostic HTTP connection future
pub type HttpConnection = Pin<Box<dyn Future<Output = Result<(), hyper::Error>> + Send>>;
Loading