add an endpoint for debugging headers

This commit is contained in:
Bryan Stitt 2023-03-09 22:51:23 -08:00
parent 4203c61a59
commit babd215e69
2 changed files with 15 additions and 0 deletions

@ -158,6 +158,7 @@ pub async fn serve(port: u16, proxy_app: Arc<Web3ProxyApp>) -> anyhow::Result<()
// //
.route("/health", get(status::health)) .route("/health", get(status::health))
.route("/status", get(status::status)) .route("/status", get(status::status))
.route("/status/headers", get(status::status_headers))
// //
// User stuff // User stuff
// //

@ -7,6 +7,8 @@ use super::{FrontendHealthCache, FrontendResponseCache, FrontendResponseCaches};
use crate::app::{Web3ProxyApp, APP_USER_AGENT}; use crate::app::{Web3ProxyApp, APP_USER_AGENT};
use axum::{http::StatusCode, response::IntoResponse, Extension, Json}; use axum::{http::StatusCode, response::IntoResponse, Extension, Json};
use axum_macros::debug_handler; use axum_macros::debug_handler;
use hashbrown::HashMap;
use http::HeaderMap;
use serde_json::json; use serde_json::json;
use std::sync::Arc; use std::sync::Arc;
@ -27,6 +29,18 @@ pub async fn health(
} }
} }
#[debug_handler]
pub async fn status_headers(headers: HeaderMap) -> impl IntoResponse {
let headers: HashMap<Option<String>, String> = headers
.into_iter()
.map(|(k, v)| (k.map(|k| k.to_string()), format!("{:?}", v)))
.collect();
let body = json!({ "headers": headers });
Json(body)
}
/// Very basic status page. /// Very basic status page.
/// ///
/// TODO: replace this with proper stats and monitoring /// TODO: replace this with proper stats and monitoring