Compare commits

...

9 Commits

Author SHA1 Message Date
eb334170d8 Merge pull request 'Update Rust crate tokio to 1.49.0' (#3) from renovate/tokio-1.x into master
All checks were successful
continuous-integration/drone/push Build is passing
2026-01-07 00:21:55 +00:00
94e9ee8ab3 Update Rust crate tokio to 1.49.0
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2026-01-06 00:22:05 +00:00
dd76599744 Merge pull request 'Update Rust crate clap to 4.5.54' (#2) from renovate/clap-4.x into master
All checks were successful
continuous-integration/drone/push Build is passing
2026-01-06 00:22:02 +00:00
e1f4dde529 Update Rust crate clap to 4.5.54
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2026-01-05 00:22:18 +00:00
2104f519eb Merge pull request 'Update Rust crate log to 0.4.29' (#1) from renovate/log-0.x into master
All checks were successful
continuous-integration/drone/push Build is passing
2025-12-04 00:15:23 +00:00
aba1121d18 Update Rust crate log to 0.4.29
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2025-12-03 00:14:40 +00:00
21fab535d4 Update
All checks were successful
continuous-integration/drone/push Build is passing
2025-11-26 12:20:10 +01:00
8b613a1b6f update
All checks were successful
continuous-integration/drone/push Build is passing
2025-11-26 12:02:30 +01:00
a26ff16bfb Minor fix 2025-11-26 11:58:53 +01:00
3 changed files with 28 additions and 12 deletions

16
Cargo.lock generated
View File

@@ -87,9 +87,9 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]] [[package]]
name = "clap" name = "clap"
version = "4.5.53" version = "4.5.54"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9e340e012a1bf4935f5282ed1436d1489548e8f72308207ea5df0e23d2d03f8" checksum = "c6e6ff9dcd79cff5cd969a17a545d79e84ab086e444102a591e288a8aa3ce394"
dependencies = [ dependencies = [
"clap_builder", "clap_builder",
"clap_derive", "clap_derive",
@@ -97,9 +97,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_builder" name = "clap_builder"
version = "4.5.53" version = "4.5.54"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d76b5d13eaa18c901fd2f7fca939fefe3a0727a953561fefdf3b2922b8569d00" checksum = "fa42cf4d2b7a41bc8f663a7cab4031ebafa1bf3875705bfaf8466dc60ab52c00"
dependencies = [ dependencies = [
"anstream", "anstream",
"anstyle", "anstyle",
@@ -245,9 +245,9 @@ dependencies = [
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.28" version = "0.4.29"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
[[package]] [[package]]
name = "memchr" name = "memchr"
@@ -486,9 +486,9 @@ dependencies = [
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.48.0" version = "1.49.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408" checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86"
dependencies = [ dependencies = [
"bytes", "bytes",
"libc", "libc",

View File

@@ -4,10 +4,10 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
log = "0.4.28" log = "0.4.29"
env_logger = "0.11.8" env_logger = "0.11.8"
clap = { version = "4.5.53", features = ["env", "derive"] } clap = { version = "4.5.54", features = ["env", "derive"] }
tokio = { version = "1.48.0", features = ["full"] } tokio = { version = "1.49.0", features = ["full"] }
rand = "0.9.2" rand = "0.9.2"
lazy_static = "1.5.0" lazy_static = "1.5.0"
httparse = "1.10.1" httparse = "1.10.1"

View File

@@ -17,7 +17,10 @@ struct Args {
#[arg(short, long, env, default_value = "x-target-host")] #[arg(short, long, env, default_value = "x-target-host")]
target_host_port_header: String, target_host_port_header: String,
/// Name of optional header that contains path to add to the request /// Name of optional header that contains path to add to the request.
///
/// If this value is defined, all clients packets are inspected in research for path to
/// manipulate
#[arg(short, long, env)] #[arg(short, long, env)]
path_prefix_header: Option<String>, path_prefix_header: Option<String>,
} }
@@ -125,6 +128,14 @@ async fn main() -> Result<(), Box<dyn Error>> {
break; break;
} }
// In case of connection reuse, we need to reanalyze data
if ARGS.path_prefix_header.is_some() &&
let Ok(Some(res))= process_headers(&buf_client[..count])
&& let Err(e) = upstream.write_all(&res.buff).await {
log::error!("[{conn_id}] Failed to write to upstream! {e}");
break;
}
if let Err(e)=upstream.write_all(&buf_client[..count]).await { if let Err(e)=upstream.write_all(&buf_client[..count]).await {
log::error!("[{conn_id}] Failed to write to upstream! {e}"); log::error!("[{conn_id}] Failed to write to upstream! {e}");
break; break;
@@ -202,13 +213,18 @@ fn process_headers(buff: &[u8]) -> anyhow::Result<Option<ProcessHeadersResult>>
let mut buff = buff.to_vec(); let mut buff = buff.to_vec();
if let Some(prefix) = prefix_path { if let Some(prefix) = prefix_path {
let pos = buff.iter().position(|c| c == &b' '); let pos = buff.iter().position(|c| c == &b' ');
log::debug!("Add path prefix to request {prefix}");
if let Some(pos) = pos { if let Some(pos) = pos {
for (num, c) in prefix.as_bytes().iter().enumerate() { for (num, c) in prefix.as_bytes().iter().enumerate() {
buff.insert(pos + 1 + num, *c); buff.insert(pos + 1 + num, *c);
} }
} else {
log::warn!("Unable to inject prefix!");
} }
} }
log::trace!("Final request: {}", String::from_utf8_lossy(&buff));
Ok(Some(ProcessHeadersResult { Ok(Some(ProcessHeadersResult {
target_host: target_host.to_string(), target_host: target_host.to_string(),
buff, buff,