Skip to content

Commit 388518a

Browse files
committed
fix(storage): Address feedback on BidiWriteObject error handling
1 parent 56269bc commit 388518a

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

google/cloud/storage/internal/grpc/configure_client_context.cc

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ namespace google {
2020
namespace cloud {
2121
namespace storage_internal {
2222
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
23+
namespace {
24+
void ApplyRoutingHeadersImpl(grpc::ClientContext& context,
25+
std::string const& bucket_name,
26+
RoutingHeaderOptions const& options) {
27+
std::string params =
28+
"bucket=" + google::cloud::internal::UrlEncode(bucket_name);
29+
if (!options.routing_token.empty()) {
30+
params += "&routing_token=" +
31+
google::cloud::internal::UrlEncode(options.routing_token);
32+
}
33+
context.AddMetadata("x-goog-request-params", std::move(params));
34+
}
35+
} // namespace
2336

2437
auto constexpr kIdempotencyTokenHeader = "x-goog-gcs-idempotency-token";
2538

@@ -46,25 +59,13 @@ void ApplyRoutingHeaders(
4659
void ApplyRoutingHeaders(grpc::ClientContext& context,
4760
google::storage::v2::WriteObjectSpec const& spec,
4861
RoutingHeaderOptions const& options) {
49-
std::string params =
50-
"bucket=" + google::cloud::internal::UrlEncode(spec.resource().bucket());
51-
if (!options.routing_token.empty()) {
52-
params += "&routing_token=" +
53-
google::cloud::internal::UrlEncode(options.routing_token);
54-
}
55-
context.AddMetadata("x-goog-request-params", params);
62+
ApplyRoutingHeadersImpl(context, spec.resource().bucket(), options);
5663
}
5764

5865
void ApplyRoutingHeaders(grpc::ClientContext& context,
5966
google::storage::v2::AppendObjectSpec const& spec,
6067
RoutingHeaderOptions const& options) {
61-
std::string params =
62-
"bucket=" + google::cloud::internal::UrlEncode(spec.bucket());
63-
if (!options.routing_token.empty()) {
64-
params += "&routing_token=" +
65-
google::cloud::internal::UrlEncode(options.routing_token);
66-
}
67-
context.AddMetadata("x-goog-request-params", params);
68+
ApplyRoutingHeadersImpl(context, spec.bucket(), options);
6869
}
6970

7071
void ApplyRoutingHeaders(grpc::ClientContext& context,

0 commit comments

Comments
 (0)