add header debug endpoint

This commit is contained in:
Bryan Stitt 2023-06-21 11:28:33 -07:00
parent 63c4f9e591
commit 662bbb296f
2 changed files with 43 additions and 1 deletions

@ -142,6 +142,7 @@ pub async fn serve(
.route("/health", get(status::health))
.route("/status", get(status::status))
.route("/status/backups_needed", get(status::backups_needed))
.route("/status/debug_request", get(status::debug_request))
//
// User stuff
//

@ -9,9 +9,12 @@ use axum::{
body::{Bytes, Full},
http::StatusCode,
response::{IntoResponse, Response},
Extension,
Extension, Json,
};
use axum_client_ip::InsecureClientIp;
use axum_macros::debug_handler;
use hashbrown::HashMap;
use http::HeaderMap;
use log::trace;
use moka::future::Cache;
use once_cell::sync::Lazy;
@ -28,6 +31,44 @@ static BACKUPS_NEEDED_FALSE: Lazy<Bytes> = Lazy::new(|| Bytes::from("false\n"));
static CONTENT_TYPE_JSON: &str = "application/json";
static CONTENT_TYPE_PLAIN: &str = "text/plain";
#[debug_handler]
pub async fn debug_request(
Extension(app): Extension<Arc<Web3ProxyApp>>,
ip: InsecureClientIp,
headers: HeaderMap,
) -> impl IntoResponse {
let (_, _, status) = _status(app).await;
let status: serde_json::Value = serde_json::from_slice(&status).unwrap();
let headers: HashMap<_, _> = headers
.into_iter()
.filter_map(|(k, v)| {
if let Some(k) = k {
let k = k.to_string();
let v = if let Ok(v) = std::str::from_utf8(v.as_bytes()) {
v.to_string()
} else {
format!("{:?}", v)
};
Some((k, v))
} else {
None
}
})
.collect();
let x = json!({
"ip": format!("{:?}", ip),
"status": status,
"headers": headers,
});
Json(x)
}
/// Health check page for load balancers to use.
#[debug_handler]
pub async fn health(