Skip to content

Commit f360e5f

Browse files
committed
fix(storage): deduplicate x-goog-api-client header in setHeadersFromCtx and adjust emulator read stall test parameters
1 parent 5baec6d commit f360e5f

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

storage/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3295,7 +3295,7 @@ func TestRetryReadStallEmulated(t *testing.T) {
32953295
client, err := NewClient(ctx, experimental.WithReadStallTimeout(
32963296
&experimental.ReadStallTimeoutConfig{
32973297
TargetPercentile: 0.99,
3298-
Min: 10 * time.Millisecond,
3298+
Min: 250 * time.Millisecond,
32993299
}))
33003300
if err != nil {
33013301
t.Fatalf("storage.NewClient: %v", err)
@@ -3361,7 +3361,7 @@ func TestGRPCRetryReadStallEmulated(t *testing.T) {
33613361
experimental.WithReadStallTimeout(
33623362
&experimental.ReadStallTimeoutConfig{
33633363
TargetPercentile: 0.99,
3364-
Min: 10 * time.Millisecond,
3364+
Min: 250 * time.Millisecond,
33653365
}),
33663366
}
33673367
if tt.bidiReads {

storage/http_client.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,14 +1736,18 @@ func setHeadersFromCtx(ctx context.Context, header http.Header) {
17361736
// Merge x-goog-api-client values into a single space-separated value.
17371737
if strings.EqualFold(k, xGoogHeaderKey) {
17381738
alreadySetValues := header.Values(xGoogHeaderKey)
1739-
vals = append(vals, alreadySetValues...)
1740-
1741-
if len(vals) > 0 {
1742-
xGoogHeader := vals[0]
1743-
for _, v := range vals[1:] {
1744-
xGoogHeader = strings.Join([]string{xGoogHeader, v}, " ")
1739+
var uniqueVals []string
1740+
seenVals := make(map[string]bool)
1741+
for _, v := range append(vals, alreadySetValues...) {
1742+
for _, part := range strings.Split(v, " ") {
1743+
if part != "" && !seenVals[part] {
1744+
seenVals[part] = true
1745+
uniqueVals = append(uniqueVals, part)
1746+
}
17451747
}
1746-
header.Set(k, xGoogHeader)
1748+
}
1749+
if len(uniqueVals) > 0 {
1750+
header.Set(k, strings.Join(uniqueVals, " "))
17471751
}
17481752
} else {
17491753
for _, v := range vals {

0 commit comments

Comments
 (0)