From 046aa72412820e03736d60ed298ed63117d1109b Mon Sep 17 00:00:00 2001 From: noahdietz Date: Tue, 12 Jul 2022 15:36:07 -0700 Subject: [PATCH 1/2] chore(storage): gRPC inject bucket ID in header for write --- storage/grpc_client.go | 3 ++- storage/internal/apiv2/metadata.go | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 storage/internal/apiv2/metadata.go diff --git a/storage/grpc_client.go b/storage/grpc_client.go index 9d253369aebb..e83f67cfbcdd 100644 --- a/storage/grpc_client.go +++ b/storage/grpc_client.go @@ -1513,7 +1513,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="+w.bucket)) + w.stream, err = w.c.raw.WriteObject(ctx) if err != nil { return nil, 0, false, err } diff --git a/storage/internal/apiv2/metadata.go b/storage/internal/apiv2/metadata.go new file mode 100644 index 000000000000..6ff86c4fb49f --- /dev/null +++ b/storage/internal/apiv2/metadata.go @@ -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...) +} From e83344d64f3db3314351b4309903feade9c58682 Mon Sep 17 00:00:00 2001 From: noahdietz Date: Tue, 26 Jul 2022 12:45:39 -0700 Subject: [PATCH 2/2] query escape value --- storage/grpc_client.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/storage/grpc_client.go b/storage/grpc_client.go index e83f67cfbcdd..91e42e625849 100644 --- a/storage/grpc_client.go +++ b/storage/grpc_client.go @@ -19,6 +19,7 @@ import ( "encoding/base64" "fmt" "io" + "net/url" "os" "cloud.google.com/go/internal/trace" @@ -1513,7 +1514,7 @@ 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 { - ctx := gapic.InsertMetadata(w.ctx, metadata.Pairs("x-goog-request-params", "bucket="+w.bucket)) + 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