Skip to content

Commit 3b8052a

Browse files
committed
ringhash: normalize uppercase in requestHashHeader from service config
With gRFC A76 (#8159), when requestHashHeader is specified from the service config it fails the validation since MD keys with uppercase letters are normalized to lowercase. We should normalize the parsed value before validation.
1 parent 732f3f3 commit 3b8052a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

xds/internal/balancer/ringhash/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func parseConfig(c json.RawMessage) (*LBConfig, error) {
7373
cfg.RequestHashHeader = ""
7474
}
7575
if cfg.RequestHashHeader != "" {
76+
cfg.RequestHashHeader = strings.ToLower(cfg.RequestHashHeader)
7677
// See rules in https://github.com/grpc/proposal/blob/master/A76-ring-hash-improvements.md#explicitly-setting-the-request-hash-key
7778
if err := metadata.ValidateKey(cfg.RequestHashHeader); err != nil {
7879
return nil, fmt.Errorf("invalid requestHashHeader %q: %v", cfg.RequestHashHeader, err)

xds/internal/balancer/ringhash/config_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ func (s) TestParseConfig(t *testing.T) {
118118
RequestHashHeader: "x-foo",
119119
},
120120
},
121+
{
122+
name: "request metadata key set with uppercase letters",
123+
js: `{"requestHashHeader": "x-FOO"}`,
124+
requestHeaderEnvVar: true,
125+
want: &LBConfig{
126+
MinRingSize: defaultMinSize,
127+
MaxRingSize: defaultMaxSize,
128+
RequestHashHeader: "x-foo",
129+
},
130+
},
121131
{
122132
name: "invalid request hash header",
123133
js: `{"requestHashHeader": "!invalid"}`,

0 commit comments

Comments
 (0)