mirror of
https://github.com/JonasunderscoreJones/jonas_jones-api.git
synced 2025-10-23 00:59:18 +02:00
added /debug/headers
This commit is contained in:
parent
6a53f1a9cb
commit
693dd6638c
3 changed files with 34 additions and 0 deletions
19
src/v1/debug/mod.rs
Normal file
19
src/v1/debug/mod.rs
Normal 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
|
||||||
|
}
|
|
@ -1,8 +1,10 @@
|
||||||
mod builtin;
|
mod builtin;
|
||||||
|
mod debug;
|
||||||
mod kcomebacks;
|
mod kcomebacks;
|
||||||
mod updates;
|
mod updates;
|
||||||
|
|
||||||
pub use builtin::get_builtin_routes as get_v1_builtin_routes;
|
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 kcomebacks::get_kcomebacks_routes as get_v1_kcomebacks_routes;
|
||||||
pub use updates::get_updates_routes as get_v1_updates_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 {
|
pub fn get_v1_routes() -> impl warp::Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
|
||||||
return get_v1_builtin_routes()
|
return get_v1_builtin_routes()
|
||||||
|
.or(get_v1_debug_routes())
|
||||||
.or(get_v1_kcomebacks_routes())
|
.or(get_v1_kcomebacks_routes())
|
||||||
.or(get_v1_updates_routes());
|
.or(get_v1_updates_routes());
|
||||||
}
|
}
|
|
@ -14,4 +14,16 @@ 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 {
|
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())
|
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()
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue