Filter :authority gRPC header

This commit is contained in:
Christian Schaible 2024-10-10 07:12:28 +02:00
parent d1b1ae040f
commit 965fa4e617
2 changed files with 3 additions and 2 deletions

View file

@ -603,12 +603,12 @@ func byteArrayToPbStruct(bytes []byte) (*structpb.Struct, error) {
return structpb.NewStruct(bodyMap)
}
// FilterAndMergeHeaders filters the "Authorization" and "B3" headers as well as
// FilterAndMergeHeaders filters ":authority", "Authorization" and "B3" headers as well as
// all headers starting with the prefixes "X-" and "STACKIT-".
// Headers are merged if there is more than one value for a given name.
func FilterAndMergeHeaders(headers map[string][]string) map[string]string {
var resultMap = make(map[string]string)
skipHeaders := []string{"authorization", "b3"}
skipHeaders := []string{":authority", "authorization", "b3"}
skipPrefixHeaders := []string{"x-", "stackit-"}
if len(headers) == 0 {

View file

@ -366,6 +366,7 @@ func Test_FilterAndMergeRequestHeaders(t *testing.T) {
headers := make(map[string][]string)
headers["Authorization"] = []string{"ey..."}
headers["B3"] = []string{"80f198ee56343ba864fe8b2a57d3eff7-e457b5a2e4d86bd1-1-05e3ac9a4f6e3b90"}
headers[":authority"] = []string{"localhost:9090"}
filteredHeaders := FilterAndMergeHeaders(headers)
assert.Equal(t, 0, len(filteredHeaders))