Skip to content

Commit

Permalink
fix enabling accept encoding with whitespaces
Browse files Browse the repository at this point in the history
Signed-off-by: Sercan Degirmenci <sercan@otsimo.com>
  • Loading branch information
sercand committed Jan 31, 2024
1 parent 02858ee commit c918f5c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/compressor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit c918f5c

Please sign in to comment.