From 693dd6638c7436d8c49f86266a6bc5374e68a76e Mon Sep 17 00:00:00 2001 From: J-onasJones Date: Fri, 15 Dec 2023 00:19:25 +0100 Subject: [PATCH] added /debug/headers --- src/v1/debug/mod.rs | 19 +++++++++++++++++++ src/v1/mod.rs | 3 +++ src/v1/updates/minecraft/mods/mod.rs | 12 ++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 src/v1/debug/mod.rs diff --git a/src/v1/debug/mod.rs b/src/v1/debug/mod.rs new file mode 100644 index 0000000..44256a0 --- /dev/null +++ b/src/v1/debug/mod.rs @@ -0,0 +1,19 @@ +use warp::Filter; + +pub fn get_debug_routes() -> impl warp::Filter + Clone { + warp::path("debug") + .and(warp::path("headers").and(warp::header::headers_cloned().map(handle_with_headers))) +} + +fn handle_with_headers( + headers: warp::http::HeaderMap, +) -> String { + // Format headers into a plain text string + let headers_text = headers + .iter() + .map(|(name, value)| format!("{}: {}\n", name.as_str(), value.to_str().unwrap_or(""))) + .collect::(); + + // Respond with the plain text-formatted headers + headers_text +} \ No newline at end of file diff --git a/src/v1/mod.rs b/src/v1/mod.rs index f4d4263..b1f4cd3 100644 --- a/src/v1/mod.rs +++ b/src/v1/mod.rs @@ -1,8 +1,10 @@ mod builtin; +mod debug; mod kcomebacks; mod updates; pub use builtin::get_builtin_routes as get_v1_builtin_routes; +pub use debug::get_debug_routes as get_v1_debug_routes; pub use kcomebacks::get_kcomebacks_routes as get_v1_kcomebacks_routes; pub use updates::get_updates_routes as get_v1_updates_routes; @@ -10,6 +12,7 @@ use warp::Filter; pub fn get_v1_routes() -> impl warp::Filter + Clone { return get_v1_builtin_routes() + .or(get_v1_debug_routes()) .or(get_v1_kcomebacks_routes()) .or(get_v1_updates_routes()); } \ No newline at end of file diff --git a/src/v1/updates/minecraft/mods/mod.rs b/src/v1/updates/minecraft/mods/mod.rs index c12631f..ce37af4 100644 --- a/src/v1/updates/minecraft/mods/mod.rs +++ b/src/v1/updates/minecraft/mods/mod.rs @@ -14,4 +14,16 @@ pub fn get_mods_paths() -> impl warp::Filter) -> String { format!("modname: {}, loadername: {}, version: {}, IP: {}", modname, loadername, version, remote_ip.unwrap_or(std::net::SocketAddr::from(([0, 0, 0, 0], 0))).ip()) +} + +fn handle_with_headers( + headers: warp::http::HeaderMap, +) -> String { + // Iterate through the headers and print them + for (name, value) in headers.iter() { + println!("Header: {}: {}", name, value.to_str().unwrap_or("Invalid UTF-8")); + } + + // Respond with a message or perform other actions as needed + "Headers received".to_string() } \ No newline at end of file