From fa9c7fc7350de6bc0f3741fc187bbc31160eea0b Mon Sep 17 00:00:00 2001 From: Christian Beilschmidt Date: Wed, 29 Oct 2025 17:48:21 +0100 Subject: [PATCH 1/4] add tests --- .github/workflows/ci.yml | 46 ++++++++++++++ Cargo.lock | 23 +++++++ Cargo.toml | 5 +- src/logger.rs | 127 +++++++++++++++++++++++++++++++++------ src/main.rs | 2 +- test-data/logged.http | 21 +++++++ 6 files changed, 202 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 test-data/logged.http diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..742c6e0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,46 @@ +name: Continuous Integration + +on: + pull_request: + branches: + - main + push: + branches: + - main + +permissions: + contents: read + +jobs: + check: + name: Lint, Format, Compile and Test + runs-on: ubuntu-latest + + steps: + - name: Checkout + id: checkout + uses: actions/checkout@v5 + + - name: Setup Rust + id: setup-rust + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + components: rustfmt, clippy + + - name: Install Dependencies & Build + id: cargo-build + run: cargo build --workspace --all-targets + + - name: Check Format + id: cargo-format-check + run: cargo fmt -- --check + + - name: Lint + id: cargo-lint + run: cargo clippy -- -D warnings + + - name: Test + id: cargo-test + run: cargo test --workspace --all-targets diff --git a/Cargo.lock b/Cargo.lock index 7671434..b1b5b55 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -155,6 +155,12 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + [[package]] name = "displaydoc" version = "0.2.5" @@ -582,6 +588,16 @@ dependencies = [ "zerovec", ] +[[package]] +name = "pretty_assertions" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ae130e2f271fbc2ac3a40fb1d07180839cdbbe443c7a27e1e3c13c5cac0116d" +dependencies = [ + "diff", + "yansi", +] + [[package]] name = "proc-macro2" version = "1.0.103" @@ -620,6 +636,7 @@ dependencies = [ "http-body-util", "hyper", "hyper-util", + "pretty_assertions", "serde_json", "tokio", "url", @@ -1023,6 +1040,12 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" +[[package]] +name = "yansi" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" + [[package]] name = "yoke" version = "0.8.1" diff --git a/Cargo.toml b/Cargo.toml index 7768379..a0035ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ unwrap_used = { level = "warn", priority = 1 } [dependencies] async-trait = "0.1" bytes = "1.4" -clap = { version = "4.4", features = ["env", "derive"] } +clap = { version = "4.5", features = ["env", "derive"] } http = "1.3" http-body-util = "0.1" hyper = { version = "1.7", features = ["full"] } # TODO: less features @@ -51,3 +51,6 @@ hyper-util = { version = "0.1", features = ["full"] } serde_json = "1.0" tokio = { version = "1", features = ["full"] } # TODO: less features url = { version = "2.5", features = ["serde"] } # TODO: remove + +[dev-dependencies] +pretty_assertions = "1.4" diff --git a/src/logger.rs b/src/logger.rs index 164b49b..7012758 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -1,8 +1,9 @@ use bytes::Bytes; use http_body_util::{BodyExt, Full}; use serde_json::Value; -use std::io; use std::io::Write; +use std::io::{self, BufWriter}; +use std::sync::{Arc, Mutex, MutexGuard}; pub struct LogEntry { pub request: hyper::Request>, @@ -17,7 +18,7 @@ pub trait RequestResponseLogger: Send + std::fmt::Debug { /// A logger that outputs request and response details to VSCode's REST log format. #[derive(Debug)] pub struct VSCodeRestLogger { - stdout: io::Stdout, + writer: LockableWriter, } #[async_trait::async_trait] @@ -30,28 +31,36 @@ impl RequestResponseLogger for VSCodeRestLogger { let request_body = body_to_string(request_body).await?; let (response_header, response_body) = response.into_parts(); let response_body = body_to_string(response_body).await?; - - let mut stdout = self.stdout.lock(); - Self::log_request(&mut stdout, request_header, request_body)?; - Self::log_response(&mut stdout, response_header, response_body)?; - stdout.flush()?; + let mut w = self.writer.lock()?; + Self::log_request(&mut w, request_header, request_body)?; + Self::log_response(&mut w, response_header, response_body)?; + w.flush()?; Ok(()) } } impl VSCodeRestLogger { - pub fn new(stdout: io::Stdout) -> Self { - Self { stdout } + pub fn from_stdout(stdout: io::Stdout) -> Self { + Self { + writer: LockableWriter::Stdout(stdout), + } + } + + #[cfg(test)] + pub fn from_buf_writer(buf_writer: Arc>>>) -> Self { + Self { + writer: LockableWriter::BufWriter(buf_writer), + } } - fn log_request( - stdout: &mut io::StdoutLock<'_>, + fn log_request( + writer: &mut W, header: http::request::Parts, body: String, ) -> io::Result<()> { writeln!( - stdout, + writer, "\n\ ###\n\ \n\ @@ -61,7 +70,7 @@ impl VSCodeRestLogger { )?; for (header, value) in header.headers.iter() { writeln!( - stdout, + writer, "{}: {}", header, value.to_str().unwrap_or("") @@ -73,19 +82,19 @@ impl VSCodeRestLogger { .and_then(|json| serde_json::to_string_pretty(&json)) .unwrap_or(body); - writeln!(stdout, "\n{body_string}")?; + writeln!(writer, "\n{body_string}")?; } Ok(()) } - fn log_response( - stdout: &mut io::StdoutLock<'_>, + fn log_response( + writer: &mut W, header: http::response::Parts, body: String, ) -> io::Result<()> { writeln!( - stdout, + writer, "\n\ ### Response ###\n\ #\n\ @@ -95,13 +104,13 @@ impl VSCodeRestLogger { )?; for (header, value) in header.headers.iter() { writeln!( - stdout, + writer, "# {key}: {value}", key = header, value = value.to_str().unwrap_or("") )?; } - writeln!(stdout, "#")?; + writeln!(writer, "#")?; if !body.is_empty() { let body_string = serde_json::from_str::(&body) @@ -109,7 +118,7 @@ impl VSCodeRestLogger { .unwrap_or(body) .replace("\n", "\n# "); // Prefix each line with a comment writeln!( - stdout, + writer, "# Body:\n\ # {body_string}\n\ #" @@ -128,3 +137,81 @@ async fn body_to_string(body: Full) -> io::Result { String::from_utf8(collected.to_bytes().to_vec()) .map_err(|e| io::Error::other(format!("Failed to convert body to string: {e}"))) } + +#[derive(Debug)] +pub enum LockableWriter { + Stdout(io::Stdout), + BufWriter(Arc>>>), +} + +impl LockableWriter { + pub fn lock<'w>(&'w mut self) -> io::Result> { + match self { + LockableWriter::Stdout(stdout) => Ok(LockableWriterGuard::Stdout(stdout.lock())), + LockableWriter::BufWriter(mutex) => { + Ok(LockableWriterGuard::BufWriter(mutex.lock().map_err( + |e| io::Error::other(format!("Failed to lock writer: {e}")), + )?)) + } + } + } +} + +#[derive(Debug)] +pub enum LockableWriterGuard<'w> { + Stdout(io::StdoutLock<'w>), + BufWriter(MutexGuard<'w, BufWriter>>), +} + +impl Write for LockableWriterGuard<'_> { + fn write(&mut self, buf: &[u8]) -> io::Result { + match self { + LockableWriterGuard::Stdout(lock) => lock.write(buf), + LockableWriterGuard::BufWriter(guard) => guard.write(buf), + } + } + + fn flush(&mut self) -> io::Result<()> { + match self { + LockableWriterGuard::Stdout(lock) => lock.flush(), + LockableWriterGuard::BufWriter(guard) => guard.flush(), + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use pretty_assertions::assert_eq; + + #[tokio::test] + async fn it_logs_requests_and_responses() { + let buf_writer = Arc::new(Mutex::new(BufWriter::new(Vec::new()))); + let mut logger = VSCodeRestLogger::from_buf_writer(buf_writer.clone()); + + let request = hyper::Request::builder() + .method("GET") + .uri("http://example.com/test") + .header("Content-Type", "application/json") + .body(Full::from(Bytes::from_static(b"{\"key\":\"value\"}"))) + .unwrap(); + + let response = hyper::Response::builder() + .status(200) + .header("Content-Type", "application/json") + .body(Full::from(Bytes::from_static( + b"{\"response_key\":\"response_value\"}", + ))) + .unwrap(); + + logger + .log_request_response(LogEntry { request, response }) + .await + .unwrap(); + + let logged_output = buf_writer.lock().unwrap().get_ref().clone(); + let logged_string = String::from_utf8(logged_output).unwrap(); + + assert_eq!(logged_string, include_str!("../test-data/logged.http")); + } +} diff --git a/src/main.rs b/src/main.rs index c873ce1..f29d273 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,7 +47,7 @@ async fn main() { .expect("Unable to resolve target address")[0]; let log_sender = match config.logger { - LoggerType::Vscode => log_channel(VSCodeRestLogger::new(io::stdout())), + LoggerType::Vscode => log_channel(VSCodeRestLogger::from_stdout(io::stdout())), }; let logger = ReplayLogger::new(log_sender, target_address); diff --git a/test-data/logged.http b/test-data/logged.http new file mode 100644 index 0000000..35431d9 --- /dev/null +++ b/test-data/logged.http @@ -0,0 +1,21 @@ + +### + +GET http://example.com/test +content-type: application/json + +{ + "key": "value" +} + +### Response ### +# +# Status Code: 200 OK +# Response Headers: +# content-type: application/json +# +# Body: +# { +# "response_key": "response_value" +# } +# From b7ba8b3eab1a00d7b98c019e5958d26883ebdf90 Mon Sep 17 00:00:00 2001 From: Christian Beilschmidt Date: Wed, 29 Oct 2025 17:55:33 +0100 Subject: [PATCH 2/4] less deps --- Cargo.lock | 182 ++------------------------------------------------ Cargo.toml | 9 ++- src/logger.rs | 1 + 3 files changed, 11 insertions(+), 181 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b1b5b55..d732973 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,35 +69,17 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" -[[package]] -name = "base64" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" - -[[package]] -name = "bitflags" -version = "2.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" - [[package]] name = "bytes" version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" -[[package]] -name = "cfg-if" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" - [[package]] name = "clap" -version = "4.5.50" +version = "4.5.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c2cfd7bf8a6017ddaa4e32ffe7403d547790db06bd171c1c53926faab501623" +checksum = "4c26d721170e0295f191a69bd9a1f93efcdb0aff38684b61ab5750468972e5f5" dependencies = [ "clap_builder", "clap_derive", @@ -105,9 +87,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.50" +version = "4.5.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a4c05b9e80c5ccd3a7ef080ad7b6ba7d6fc00a985b8b157197075677c82c7a0" +checksum = "75835f0c7bf681bfd05abe44e965760fea999a5286c6eb2d59883634fd02011a" dependencies = [ "anstream", "anstyle", @@ -139,22 +121,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "diff" version = "0.1.13" @@ -214,24 +180,6 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" -[[package]] -name = "futures-task" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" - -[[package]] -name = "futures-util" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" -dependencies = [ - "futures-core", - "futures-task", - "pin-project-lite", - "pin-utils", -] - [[package]] name = "h2" version = "0.4.12" @@ -338,24 +286,16 @@ version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c6995591a8f1380fcb4ba966a252a4b29188d51d2b89e3a252f5305be65aea8" dependencies = [ - "base64", "bytes", "futures-channel", "futures-core", - "futures-util", "http", "http-body", "hyper", - "ipnet", - "libc", - "percent-encoding", "pin-project-lite", - "socket2", - "system-configuration", "tokio", "tower-service", "tracing", - "windows-registry", ] [[package]] @@ -470,12 +410,6 @@ dependencies = [ "hashbrown", ] -[[package]] -name = "ipnet" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" - [[package]] name = "is_terminal_polyfill" version = "1.70.2" @@ -500,15 +434,6 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" -[[package]] -name = "lock_api" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" -dependencies = [ - "scopeguard", -] - [[package]] name = "memchr" version = "2.7.6" @@ -538,29 +463,6 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" -[[package]] -name = "parking_lot" -version = "0.12.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-link 0.2.1", -] - [[package]] name = "percent-encoding" version = "2.3.2" @@ -616,15 +518,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" -dependencies = [ - "bitflags", -] - [[package]] name = "request-logging-proxy" version = "0.1.0" @@ -648,12 +541,6 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "serde" version = "1.0.228" @@ -762,27 +649,6 @@ dependencies = [ "syn", ] -[[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "tinystr" version = "0.8.2" @@ -802,7 +668,6 @@ dependencies = [ "bytes", "libc", "mio", - "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", @@ -910,47 +775,12 @@ version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" -[[package]] -name = "windows-link" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" - [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" -[[package]] -name = "windows-registry" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a9ed28765efc97bbc954883f4e6796c33a06546ebafacbabee9696967499e" -dependencies = [ - "windows-link 0.1.3", - "windows-result", - "windows-strings", -] - -[[package]] -name = "windows-result" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" -dependencies = [ - "windows-link 0.1.3", -] - -[[package]] -name = "windows-strings" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" -dependencies = [ - "windows-link 0.1.3", -] - [[package]] name = "windows-sys" version = "0.60.2" @@ -966,7 +796,7 @@ version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" dependencies = [ - "windows-link 0.2.1", + "windows-link", ] [[package]] @@ -975,7 +805,7 @@ version = "0.53.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" dependencies = [ - "windows-link 0.2.1", + "windows-link", "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", diff --git a/Cargo.toml b/Cargo.toml index a0035ff..0f67e86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,6 @@ pedantic = { level = "warn", priority = 0 } correctness = "deny" # disable some pedantic lints -result_large_err = { level = "allow", priority = 1 } # TODO: investigate this cast_possible_truncation = { level = "allow", priority = 1 } cast_possible_wrap = { level = "allow", priority = 1 } cast_precision_loss = { level = "allow", priority = 1 } @@ -46,11 +45,11 @@ bytes = "1.4" clap = { version = "4.5", features = ["env", "derive"] } http = "1.3" http-body-util = "0.1" -hyper = { version = "1.7", features = ["full"] } # TODO: less features -hyper-util = { version = "0.1", features = ["full"] } +hyper = { version = "1.7", features = [] } +hyper-util = { version = "0.1", features = ["client", "server-auto", "server-graceful"] } serde_json = "1.0" -tokio = { version = "1", features = ["full"] } # TODO: less features -url = { version = "2.5", features = ["serde"] } # TODO: remove +tokio = { version = "1", features = ["macros", "rt-multi-thread", "signal"] } # TODO: less features +url = { version = "2.5", features = [] } # TODO: remove [dev-dependencies] pretty_assertions = "1.4" diff --git a/src/logger.rs b/src/logger.rs index 7012758..5b1214d 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -141,6 +141,7 @@ async fn body_to_string(body: Full) -> io::Result { #[derive(Debug)] pub enum LockableWriter { Stdout(io::Stdout), + #[allow(dead_code)] // for tests BufWriter(Arc>>>), } From fc67aa0292718f2fb3e59b18d50a85cd05690828 Mon Sep 17 00:00:00 2001 From: Christian Beilschmidt Date: Wed, 29 Oct 2025 18:05:19 +0100 Subject: [PATCH 3/4] readme --- README.md | 57 +++++++++++++++++++++++++++++++++++++++++++++++++-- src/config.rs | 2 +- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6a5a3d0..7f87564 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,55 @@ -# request-logging-proxy -A proxy server that forwards requests and responds and logs them to stdout. +[![CI](https://github.com/geo-engine/request-logging-proxy/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/geo-engine/request-logging-proxy/actions/workflows/ci.yml?branch=main) + +# Request Logging Proxy + +A proxy server that forwards requests and responses and logs them to stdout. + +## Building + +```bash +cargo build --workspace --all-targets +``` + +## Running + +```bash +cargo run -- --target-url http://localhost:8484 +``` + +This starts the proxy server on port `8123` forwarding requests to `http://localhost:8484`. +It logs requests and responses to stdout in the "vscode" format. +You can customize the target URL, port, and logger format: + +```bash +cargo run -- \ + --target-url http://localhost:8484 \ + --port 8123 \ + --logger vscode +``` + +## Testing + +```bash +cargo test --workspace +``` + +## Installing + +```bash +cargo install --path . +``` + +```bash +request-logging-proxy --target-url http://localhost:8484 +``` + +## Logger Formats + +- `vscode`: Logs requests and responses in a format compatible with VSCode's REST (.http) extension. + +If you want other formats, feel free to open an issue or a pull request. + +## License + +This project is licensed under the Apache License Version 2.0. +See the [LICENSE](LICENSE) file for details. diff --git a/src/config.rs b/src/config.rs index a842b91..b298173 100644 --- a/src/config.rs +++ b/src/config.rs @@ -13,7 +13,7 @@ pub struct Config { #[arg(long, default_value_t = 8123, env = "PORT")] pub port: u16, - /// The type of logger to use (e.g., "console", "file") + /// The type of logger to use (e.g., "vscode") #[arg(long, default_value_t = LoggerType::Vscode, env = "LOGGER")] pub logger: LoggerType, } From 1ab0fb7115e8085ec87b72ba7a4db46f44e0f001 Mon Sep 17 00:00:00 2001 From: Christian Beilschmidt Date: Wed, 29 Oct 2025 18:06:25 +0100 Subject: [PATCH 4/4] readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7f87564..22e34ed 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -[![CI](https://github.com/geo-engine/request-logging-proxy/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/geo-engine/request-logging-proxy/actions/workflows/ci.yml?branch=main) - # Request Logging Proxy +[![CI](https://github.com/geo-engine/request-logging-proxy/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/geo-engine/request-logging-proxy/actions/workflows/ci.yml?branch=main) + A proxy server that forwards requests and responses and logs them to stdout. ## Building