Compare commits
9 Commits
d8ea9db3c2
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| eb334170d8 | |||
| 94e9ee8ab3 | |||
| dd76599744 | |||
| e1f4dde529 | |||
| 2104f519eb | |||
| aba1121d18 | |||
| 21fab535d4 | |||
| 8b613a1b6f | |||
| a26ff16bfb |
16
Cargo.lock
generated
16
Cargo.lock
generated
@@ -87,9 +87,9 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.53"
|
||||
version = "4.5.54"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9e340e012a1bf4935f5282ed1436d1489548e8f72308207ea5df0e23d2d03f8"
|
||||
checksum = "c6e6ff9dcd79cff5cd969a17a545d79e84ab086e444102a591e288a8aa3ce394"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
@@ -97,9 +97,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.53"
|
||||
version = "4.5.54"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d76b5d13eaa18c901fd2f7fca939fefe3a0727a953561fefdf3b2922b8569d00"
|
||||
checksum = "fa42cf4d2b7a41bc8f663a7cab4031ebafa1bf3875705bfaf8466dc60ab52c00"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
@@ -245,9 +245,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.28"
|
||||
version = "0.4.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
|
||||
checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
@@ -486,9 +486,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.48.0"
|
||||
version = "1.49.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408"
|
||||
checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"libc",
|
||||
|
||||
@@ -4,10 +4,10 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
log = "0.4.28"
|
||||
log = "0.4.29"
|
||||
env_logger = "0.11.8"
|
||||
clap = { version = "4.5.53", features = ["env", "derive"] }
|
||||
tokio = { version = "1.48.0", features = ["full"] }
|
||||
clap = { version = "4.5.54", features = ["env", "derive"] }
|
||||
tokio = { version = "1.49.0", features = ["full"] }
|
||||
rand = "0.9.2"
|
||||
lazy_static = "1.5.0"
|
||||
httparse = "1.10.1"
|
||||
|
||||
18
src/main.rs
18
src/main.rs
@@ -17,7 +17,10 @@ struct Args {
|
||||
#[arg(short, long, env, default_value = "x-target-host")]
|
||||
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)]
|
||||
path_prefix_header: Option<String>,
|
||||
}
|
||||
@@ -125,6 +128,14 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
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 {
|
||||
log::error!("[{conn_id}] Failed to write to upstream! {e}");
|
||||
break;
|
||||
@@ -202,13 +213,18 @@ fn process_headers(buff: &[u8]) -> anyhow::Result<Option<ProcessHeadersResult>>
|
||||
let mut buff = buff.to_vec();
|
||||
if let Some(prefix) = prefix_path {
|
||||
let pos = buff.iter().position(|c| c == &b' ');
|
||||
log::debug!("Add path prefix to request {prefix}");
|
||||
if let Some(pos) = pos {
|
||||
for (num, c) in prefix.as_bytes().iter().enumerate() {
|
||||
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 {
|
||||
target_host: target_host.to_string(),
|
||||
buff,
|
||||
|
||||
Reference in New Issue
Block a user