@@ -25,6 +25,7 @@ import (
2525
2626 xxhash "github.com/cespare/xxhash/v2"
2727 "github.com/google/go-cmp/cmp"
28+ "google.golang.org/grpc/internal/grpcutil"
2829 iresolver "google.golang.org/grpc/internal/resolver"
2930 "google.golang.org/grpc/metadata"
3031 _ "google.golang.org/grpc/xds/internal/balancer/cdsbalancer" // To parse LB config
@@ -106,6 +107,35 @@ func (s) TestGenerateRequestHash(t *testing.T) {
106107 Method : "/some-method" ,
107108 },
108109 },
110+ // Tests that bin headers are skipped.
111+ {
112+ name : "skip-bin" ,
113+ hashPolicies : []* xdsresource.HashPolicy {{
114+ HashPolicyType : xdsresource .HashPolicyTypeHeader ,
115+ HeaderName : "something-bin" ,
116+ }, {
117+ HashPolicyType : xdsresource .HashPolicyTypeChannelID ,
118+ }},
119+ requestHashWant : channelID ,
120+ rpcInfo : iresolver.RPCInfo {
121+ Context : metadata .NewOutgoingContext (context .Background (), metadata .Pairs ("something-bin" , "xyz" )),
122+ },
123+ },
124+ // Tests that extra metadata takes precedence over the user's metadata.
125+ {
126+ name : "extra-metadata" ,
127+ hashPolicies : []* xdsresource.HashPolicy {{
128+ HashPolicyType : xdsresource .HashPolicyTypeHeader ,
129+ HeaderName : "content-type" ,
130+ }},
131+ requestHashWant : xxhash .Sum64String ("grpc value" ),
132+ rpcInfo : iresolver.RPCInfo {
133+ Context : grpcutil .WithExtraMetadata (
134+ metadata .NewOutgoingContext (context .Background (), metadata .Pairs ("content-type" , "user value" )),
135+ metadata .Pairs ("content-type" , "grpc value" ),
136+ ),
137+ },
138+ },
109139 }
110140 for _ , test := range tests {
111141 t .Run (test .name , func (t * testing.T ) {
0 commit comments