summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-03-17 21:35:25 +0100
committermetamuffin <metamuffin@disroot.org>2025-03-17 21:35:25 +0100
commitc19e992b557c169ee0fa765c29c8ee3b4e897946 (patch)
treed191876aa109e17578dcbca647e6a14b5043141f
parent73768c25588779bce122c0e3daa023024e972298 (diff)
downloadgnix-c19e992b557c169ee0fa765c29c8ee3b4e897946.tar
gnix-c19e992b557c169ee0fa765c29c8ee3b4e897946.tar.bz2
gnix-c19e992b557c169ee0fa765c29c8ee3b4e897946.tar.zst
fix proxy module for h3. h3 still half-broken though
-rw-r--r--src/error.rs2
-rw-r--r--src/main.rs14
-rw-r--r--src/modules/proxy.rs2
3 files changed, 13 insertions, 5 deletions
diff --git a/src/error.rs b/src/error.rs
index 3950b80..d988ffa 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -6,7 +6,7 @@ pub enum ServiceError {
RequestTaken,
#[error("limit reached. try again")]
Limit(#[from] tokio::sync::TryAcquireError),
- #[error("hyper error")]
+ #[error("hyper error: {0}")]
Hyper(hyper::Error),
#[error("h3 error: {0}")]
H3(h3::Error),
diff --git a/src/main.rs b/src/main.rs
index 08f306d..ee33d3f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -224,9 +224,14 @@ async fn serve_h3(state: Arc<State>) -> Result<()> {
let state = state.clone();
tokio::spawn(async move {
let addr = conn.remote_address(); // TODO wait for validatation (or not?)
+ debug!("h3 connection attempt from {addr}");
let Ok(_sem) = state.l_incoming.try_acquire() else {
return conn.refuse();
};
+ let conn = match conn.accept() {
+ Ok(conn) => conn,
+ Err(e) => return warn!("quic accep failed: {e}"),
+ };
let conn = match conn.await {
Ok(conn) => conn,
Err(e) => return warn!("quic connection failed: {e}"),
@@ -239,6 +244,7 @@ async fn serve_h3(state: Arc<State>) -> Result<()> {
Ok(conn) => conn,
Err(e) => return warn!("h3 accept failed {e}"),
};
+ debug!("h3 stream from {addr}");
loop {
match conn.accept().await {
Ok(Some((req, stream))) => {
@@ -262,7 +268,7 @@ async fn serve_h3(state: Arc<State>) -> Result<()> {
let resp = Response::from_parts(parts, ());
if let Err(e) = send.send_response(resp).await {
- warn!("h3 response send error: {e}");
+ debug!("h3 response send error: {e}");
return;
};
while let Some(frame) = body.frame().await {
@@ -271,13 +277,13 @@ async fn serve_h3(state: Arc<State>) -> Result<()> {
if frame.is_data() {
let data = frame.into_data().unwrap();
if let Err(e) = send.send_data(data).await {
- warn!("h3 body send error: {e}");
+ debug!("h3 body send error: {e}");
return;
}
} else if frame.is_trailers() {
let trailers = frame.into_trailers().unwrap();
if let Err(e) = send.send_trailers(trailers).await {
- warn!("h3 trailers send error: {e}");
+ debug!("h3 trailers send error: {e}");
return;
}
}
@@ -286,7 +292,7 @@ async fn serve_h3(state: Arc<State>) -> Result<()> {
}
}
if let Err(e) = send.finish().await {
- warn!("h3 response finish error: {e}");
+ debug!("h3 response finish error: {e}");
return;
}
}
diff --git a/src/modules/proxy.rs b/src/modules/proxy.rs
index 2fa3538..a0e8d85 100644
--- a/src/modules/proxy.rs
+++ b/src/modules/proxy.rs
@@ -1,6 +1,7 @@
use super::{Node, NodeContext, NodeKind, NodeRequest, NodeResponse};
use crate::ServiceError;
use futures::Future;
+use http::Version;
use http_body_util::BodyExt;
use hyper::{http::HeaderValue, upgrade::OnUpgrade, StatusCode};
use hyper_util::rt::TokioIo;
@@ -41,6 +42,7 @@ impl Node for Proxy {
mut request: NodeRequest,
) -> Pin<Box<dyn Future<Output = Result<NodeResponse, ServiceError>> + Send + Sync + 'a>> {
Box::pin(async move {
+ *request.version_mut() = Version::HTTP_11; // totally not a lie
if self.set_real_ip {
request.headers_mut().insert(
"x-real-ip",