Skip to content

Commit c918f5c

Browse files
committed
fix enabling accept encoding with whitespaces
Signed-off-by: Sercan Degirmenci <[email protected]>
1 parent 02858ee commit c918f5c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

server.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,7 +2119,11 @@ func ClientSupportedCompressors(ctx context.Context) ([]string, error) {
21192119
return nil, fmt.Errorf("failed to fetch the stream from the given context %v", ctx)
21202120
}
21212121

2122-
return strings.Split(stream.ClientAdvertisedCompressors(), ","), nil
2122+
values := strings.Split(stream.ClientAdvertisedCompressors(), ",")
2123+
for i, v := range values {
2124+
values[i] = strings.TrimSpace(v)
2125+
}
2126+
return values, nil
21232127
}
21242128

21252129
// SetTrailer sets the trailer metadata that will be sent when an RPC returns.
@@ -2169,7 +2173,7 @@ func validateSendCompressor(name, clientCompressors string) error {
21692173
}
21702174

21712175
for _, c := range strings.Split(clientCompressors, ",") {
2172-
if c == name {
2176+
if strings.TrimSpace(c) == name {
21732177
return nil // found match
21742178
}
21752179
}

test/compressor_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,13 @@ func (s) TestClientSupportedCompressors(t *testing.T) {
566566
),
567567
want: []string{"gzip"},
568568
},
569+
{
570+
desc: "With additional grpc-accept-encoding header with spaces between values",
571+
ctx: metadata.AppendToOutgoingContext(ctx,
572+
"grpc-accept-encoding", "identity, deflate",
573+
),
574+
want: []string{"gzip", "identity", "deflate"},
575+
},
569576
} {
570577
t.Run(tt.desc, func(t *testing.T) {
571578
ss := &stubserver.StubServer{

0 commit comments

Comments
 (0)