From 3ddcdc268d88595eb2f3721f7dc87970a6c3ab6e Mon Sep 17 00:00:00 2001 From: dfawley Date: Wed, 26 Jul 2017 10:50:56 -0700 Subject: [PATCH] Make all "grpc-" metadata field names reserved (#1391) --- transport/http_util.go | 17 ++++++----------- transport/transport_test.go | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/transport/http_util.go b/transport/http_util.go index 685c6fbf..c2bb0e53 100644 --- a/transport/http_util.go +++ b/transport/http_util.go @@ -121,19 +121,14 @@ func isReservedHeader(hdr string) bool { if hdr != "" && hdr[0] == ':' { return true } - switch hdr { - case "content-type", - "grpc-message-type", - "grpc-encoding", - "grpc-message", - "grpc-status", - "grpc-timeout", - "grpc-status-details-bin", - "te": + if strings.HasPrefix(hdr, "grpc-") { return true - default: - return false } + switch hdr { + case "content-type", "te": + return true + } + return false } // isWhitelistedPseudoHeader checks whether hdr belongs to HTTP2 pseudoheaders diff --git a/transport/transport_test.go b/transport/transport_test.go index 86104788..97e63344 100644 --- a/transport/transport_test.go +++ b/transport/transport_test.go @@ -1577,7 +1577,7 @@ func TestIsReservedHeader(t *testing.T) { {"grpc-encoding", true}, {"grpc-message", true}, {"grpc-status", true}, - {"grpc-timeout", true}, + {"grpc-anything-else99999", true}, {"te", true}, } for _, tt := range tests {