Skip to content

Commit b0bac64

Browse files
authored
fix: ApiKeyOption without UserProjectOption (#14748)
1 parent 0a97e1a commit b0bac64

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

google/cloud/internal/rest_set_metadata.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void SetMetadata(RestContext& context, Options const& options,
3838
if (options.has<QuotaUserOption>()) {
3939
context.AddHeader("x-goog-quota-user", options.get<QuotaUserOption>());
4040
}
41-
if (options.has<UserProjectOption>()) {
41+
if (options.has<ApiKeyOption>()) {
4242
context.AddHeader("x-goog-api-key", options.get<ApiKeyOption>());
4343
}
4444
if (options.has<FieldMaskOption>()) {

google/cloud/internal/rest_set_metadata_test.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace rest_internal {
2525
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
2626
namespace {
2727

28+
using ::testing::Contains;
2829
using ::testing::ElementsAre;
2930
using ::testing::Pair;
3031
using ::testing::UnorderedElementsAre;
@@ -71,6 +72,14 @@ TEST(RestContextTest, SetMetadataFull) {
7172
Pair("custom-header-2", ElementsAre("v2"))));
7273
}
7374

75+
TEST(RestContextTest, Regression14745) {
76+
RestContext lhs;
77+
SetMetadata(lhs, Options{}.set<ApiKeyOption>("api-key"), {},
78+
"api-client-header");
79+
EXPECT_THAT(lhs.headers(),
80+
Contains(Pair("x-goog-api-key", ElementsAre("api-key"))));
81+
}
82+
7483
} // namespace
7584
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
7685
} // namespace rest_internal

0 commit comments

Comments
 (0)