Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore double value for grpc-accept-encoding header #2342

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Columns in the HTML Outbounds table on the debug page now properly line up
with header rows.

### Changed
- Allow multiple values for the header `grpc-accept-encoding`. Only one (random) value will be used anyway,
but no error will be returned.

## [1.75.3] - 2024-12-04
### Added
- Noop resolver to use in clients with custom load balancing.
Expand Down
19 changes: 17 additions & 2 deletions transport/grpc/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ const (

baseContentType = "application/grpc"
contentTypeHeader = "content-type"

// grpcAcceptEncodingHeader is the header name that keeps the list of available compressors,
// applicable for both request and response headers. Usually consumed by grpc, but the
// value is kept in metadata and available in application code.
grpcAcceptEncodingHeader = "grpc-accept-encoding"
)

// TODO: there are way too many repeat calls to strings.ToLower
Expand Down Expand Up @@ -128,7 +133,12 @@ func metadataToTransportRequest(md metadata.MD) (*transport.Request, error) {
case 1:
value = values[0]
default:
return nil, yarpcerrors.InvalidArgumentErrorf("header has more than one value: %s:%v", header, values)
// TODO (https://github.com/yarpc/yarpc-go/issues/2265) don't pass this values to application code
if header == grpcAcceptEncodingHeader {
value = values[0]
} else {
return nil, yarpcerrors.InvalidArgumentErrorf("header has more than one value: %s:%v", header, values)
}
}
header = transport.CanonicalizeHeaderKey(header)
switch header {
Expand Down Expand Up @@ -213,7 +223,12 @@ func getApplicationHeaders(md metadata.MD) (transport.Headers, error) {
case 1:
value = values[0]
default:
return headers, yarpcerrors.InvalidArgumentErrorf("header has more than one value: %s:%v", header, values)
// TODO (https://github.com/yarpc/yarpc-go/issues/2265) don't pass this values to application code
if header == grpcAcceptEncodingHeader {
value = values[0]
} else {
return headers, yarpcerrors.InvalidArgumentErrorf("header has more than one value: %s:%v", header, values)
}
}
headers = headers.With(header, value)
}
Expand Down
29 changes: 29 additions & 0 deletions transport/grpc/headers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,22 @@ func TestMetadataToTransportRequest(t *testing.T) {
}),
},
},
{
Name: "Double grpc-accept-encoding value",
MD: metadata.Pairs(
grpcAcceptEncodingHeader, "gzip",
grpcAcceptEncodingHeader, "zlib",
"foo", "bar",
"baz", "bat",
),
TransportRequest: &transport.Request{
Headers: transport.HeadersFromMap(map[string]string{
"foo": "bar",
"baz": "bat",
"grpc-accept-encoding": "gzip",
}),
},
},
}
for _, tt := range tests {
t.Run(tt.Name, func(t *testing.T) {
Expand Down Expand Up @@ -253,6 +269,19 @@ func TestGetApplicationHeaders(t *testing.T) {
},
wantErr: "header has more than one value: test-header-dup:[test-value-1 test-value-2]",
},
{
msg: "Multiple value for grpc-accept-encoding header",
meta: metadata.MD{
"test-header-valid-1": []string{"test-value-1"},
"test-Header-Valid-2": []string{"test-value-2"},
"grpc-accept-encoding": []string{"gzip", "zlib"},
},
wantHeaders: map[string]string{
"test-header-valid-1": "test-value-1",
"test-header-valid-2": "test-value-2",
"grpc-accept-encoding": "gzip",
},
},
}

for _, tt := range tests {
Expand Down