Skip to content

impl(rest): update AuthenticationHeader method to return multiple headers#16061

Draft
scotthart wants to merge 12 commits intogoogleapis:mainfrom
scotthart:rab_prototype_2
Draft

impl(rest): update AuthenticationHeader method to return multiple headers#16061
scotthart wants to merge 12 commits intogoogleapis:mainfrom
scotthart:rab_prototype_2

Conversation

@scotthart
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors HTTP header handling by introducing the HttpHeaderName class for case-insensitive keys and a dedicated HttpHeader class, replacing previous implementations that used raw maps and string pairs. The authentication logic was updated to support multiple headers through the new AuthenticationHeaders and AuthenticationHeadersJoined functions. Feedback indicates that joining multiple headers with a semicolon in AuthenticationHeadersJoined is non-standard and may result in invalid HTTP fields; it is recommended to use \r\n or add assertions if only one header is expected. Additionally, a comment in http_header.h regarding the preservation of header case is now outdated and should be corrected.

Comment on lines +66 to +69
return absl::StrJoin(*headers, ";",
[](std::string* s, rest_internal::HttpHeader const& h) {
*s += std::string{h};
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Joining multiple HTTP headers with a semicolon is not a standard practice for representing multiple headers. This will produce a string like header1: value1;header2: value2, which is not a valid HTTP header field. HTTP headers should be on separate lines, separated by \r\n.

If callers of this function might receive multiple headers, this implementation could cause issues. If this function is only intended to handle a single header, it would be safer to add an assertion (e.g., GCP_ASSERT(headers->size() <= 1);) to make this assumption explicit and prevent future problems.

References
  1. Prefer defensive code, such as explicit ok() checks, even if they seem redundant based on the current implementation of a framework, as the framework's contract may change in the future.

Comment on lines 132 to 133
// While the RFCs indicate that header keys are case-insensitive, no attempt
// to convert them to all lowercase is made. Header keys are printed in the
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This comment is now outdated. With the introduction of HttpHeaderName, header keys are converted to lowercase, and the original case is lost. When printed, they will be in lowercase. This comment should be removed or updated to avoid confusion.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 96.77419% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.68%. Comparing base (5b7b3c8) to head (ae7fe69).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
google/cloud/internal/http_header.cc 90.00% 2 Missing ⚠️
...ts/service_account_credentials_integration_test.cc 0.00% 2 Missing ⚠️
...oud/bigquery/v2/minimal/internal/rest_stub_utils.h 0.00% 1 Missing ⚠️
google/cloud/internal/rest_request.cc 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16061      +/-   ##
==========================================
- Coverage   92.69%   92.68%   -0.02%     
==========================================
  Files        2343     2343              
  Lines      216541   216577      +36     
==========================================
+ Hits       200729   200740      +11     
- Misses      15812    15837      +25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant