added /debug/headers

This commit is contained in:
J-onasJones 2023-12-15 00:19:25 +01:00
parent 6a53f1a9cb
commit 693dd6638c
3 changed files with 34 additions and 0 deletions

19
src/v1/debug/mod.rs Normal file
View file

@ -0,0 +1,19 @@
use warp::Filter;
pub fn get_debug_routes() -> impl warp::Filter<Extract = impl warp::Reply, Error = warp::Rejection> + 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::<String>();
// Respond with the plain text-formatted headers
headers_text
}

View file

@ -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<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
return get_v1_builtin_routes()
.or(get_v1_debug_routes())
.or(get_v1_kcomebacks_routes())
.or(get_v1_updates_routes());
}

View file

@ -15,3 +15,15 @@ pub fn get_mods_paths() -> impl warp::Filter<Extract = impl warp::Reply, Error =
fn handle_path(modname: String, loadername: String, version: String, remote_ip: Option<std::net::SocketAddr>) -> 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()
}