From c918f5c8d1ef104be546f02041d18b709c4b6cf0 Mon Sep 17 00:00:00 2001 From: Sercan Degirmenci Date: Wed, 31 Jan 2024 12:46:06 +0300 Subject: [PATCH] fix enabling accept encoding with whitespaces Signed-off-by: Sercan Degirmenci --- server.go | 8 ++++++-- test/compressor_test.go | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/server.go b/server.go index e89c5ac6136c..607a5139853a 100644 --- a/server.go +++ b/server.go @@ -2119,7 +2119,11 @@ func ClientSupportedCompressors(ctx context.Context) ([]string, error) { return nil, fmt.Errorf("failed to fetch the stream from the given context %v", ctx) } - return strings.Split(stream.ClientAdvertisedCompressors(), ","), nil + values := strings.Split(stream.ClientAdvertisedCompressors(), ",") + for i, v := range values { + values[i] = strings.TrimSpace(v) + } + return values, nil } // SetTrailer sets the trailer metadata that will be sent when an RPC returns. @@ -2169,7 +2173,7 @@ func validateSendCompressor(name, clientCompressors string) error { } for _, c := range strings.Split(clientCompressors, ",") { - if c == name { + if strings.TrimSpace(c) == name { return nil // found match } } diff --git a/test/compressor_test.go b/test/compressor_test.go index a18d14f4ac73..7f3abb908c2e 100644 --- a/test/compressor_test.go +++ b/test/compressor_test.go @@ -566,6 +566,13 @@ func (s) TestClientSupportedCompressors(t *testing.T) { ), want: []string{"gzip"}, }, + { + desc: "With additional grpc-accept-encoding header with spaces between values", + ctx: metadata.AppendToOutgoingContext(ctx, + "grpc-accept-encoding", "identity, deflate", + ), + want: []string{"gzip", "identity", "deflate"}, + }, } { t.Run(tt.desc, func(t *testing.T) { ss := &stubserver.StubServer{