Skip to content

Commit

Permalink
chore(storage): gRPC inject bucket ID in header for write (#6328)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz authored Aug 1, 2022
1 parent 7bfd4ec commit 5ee0de3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion storage/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/base64"
"fmt"
"io"
"net/url"
"os"

"cloud.google.com/go/internal/trace"
Expand Down Expand Up @@ -1514,7 +1515,8 @@ func (w *gRPCWriter) uploadBuffer(recvd int, start int64, doneReading bool) (*st
// The first message on the WriteObject stream must either be the
// Object or the Resumable Upload ID.
if first {
w.stream, err = w.c.raw.WriteObject(w.ctx)
ctx := gapic.InsertMetadata(w.ctx, metadata.Pairs("x-goog-request-params", "bucket="+url.QueryEscape(w.bucket)))
w.stream, err = w.c.raw.WriteObject(ctx)
if err != nil {
return nil, 0, false, err
}
Expand Down
26 changes: 26 additions & 0 deletions storage/internal/apiv2/metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package storage

import (
"context"

"google.golang.org/grpc/metadata"
)

// InsertMetadata inserts the given gRPC metadata into the outgoing context.
func InsertMetadata(ctx context.Context, mds ...metadata.MD) context.Context {
return insertMetadata(ctx, mds...)
}

0 comments on commit 5ee0de3

Please sign in to comment.