Skip to content

Commit

Permalink
feat: parse client names to groups (#1262)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhani-cw authored Jun 28, 2024
1 parent 576001a commit 572fa19
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/eth/rpc/rpc_client_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ impl Display for RpcClientApp {
}
}

impl RpcClientApp {
/// Parse known client application name to groups.
pub fn parse(name: &str) -> RpcClientApp {
let name = name.trim().trim_end_matches('/').to_ascii_lowercase();
let name = match name {
n if n.starts_with("banking") => format!("banking::{}", n),
n if n.starts_with("issuing") || n.starts_with("infinitecard") => format!("issuing::{}", n),
n if n.starts_with("lending") => format!("lending::{}", n),
n if n == "blockscout" || n == "golani" || n == "tx-replayer" => format!("infra::{}", n),
n => format!("other::{}", n),
};
RpcClientApp::Identified(name)
}
}

// -----------------------------------------------------------------------------
// Serialization / Deserialization
// -----------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions src/eth/rpc/rpc_http_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ fn parse_client_app(headers: &HeaderMap<HeaderValue>, uri: &Uri) -> RpcClientApp
}

// try http headers
for header in ["x-app", "x-client"] {
for header in ["x-app", "x-stratus-app", "x-client", "x-stratus-client"] {
if let Some(client_app) = headers.get(header) {
let Ok(client_app) = client_app.to_str() else {
tracing::warn!(%header, value = ?client_app, "failed to parse http header as ascii string");
continue;
};
let client_app = normalize(client_app);
if not(client_app.is_empty()) {
return RpcClientApp::Identified(client_app.to_owned());
return RpcClientApp::parse(&client_app);
}
}
}
Expand All @@ -77,7 +77,7 @@ fn parse_client_app(headers: &HeaderMap<HeaderValue>, uri: &Uri) -> RpcClientApp
if let Some(client_app) = query_params.get(param) {
let client_app = normalize(client_app);
if not(client_app.is_empty()) {
return RpcClientApp::Identified(client_app.to_owned());
return RpcClientApp::parse(&client_app);
}
}
}
Expand Down

0 comments on commit 572fa19

Please sign in to comment.