Skip to content

Commit

Permalink
rpc: properly handle the various content-type's that are considered gRPC
Browse files Browse the repository at this point in the history
Properly handle identifying gRPC traffic by performing a prefix
comparision on a request's content-type header instead of a full
equality check.
  • Loading branch information
bmwill committed Dec 11, 2024
1 parent b4bf711 commit f296565
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions crates/sui-rpc-api/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f296565

Please sign in to comment.