From f2965657d87e7bb7d1ff05e0869d9587a4853a32 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 11 Dec 2024 10:35:33 -0600 Subject: [PATCH] rpc: properly handle the various content-type's that are considered gRPC Properly handle identifying gRPC traffic by performing a prefix comparision on a request's content-type header instead of a full equality check. --- crates/sui-rpc-api/src/metrics.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/sui-rpc-api/src/metrics.rs b/crates/sui-rpc-api/src/metrics.rs index df2c9723ecf25..4a114278567f8 100644 --- a/crates/sui-rpc-api/src/metrics.rs +++ b/crates/sui-rpc-api/src/metrics.rs @@ -113,8 +113,15 @@ impl ResponseHandler for RpcMetricsCallbackHandler { let status = if response .headers .get(&http::header::CONTENT_TYPE) - .is_some_and(|header| header == tonic::metadata::GRPC_CONTENT_TYPE) - { + .is_some_and(|content_type| { + content_type + .as_bytes() + // check if the content-type starts_with 'application/grpc' in order to + // consider this as a gRPC request. A prefix comparison is done instead of a + // full equality check in order to account for the various types of + // content-types that are considered as gRPC traffic. + .starts_with(tonic::metadata::GRPC_CONTENT_TYPE.as_bytes()) + }) { let code = response .headers .get(&GRPC_STATUS)