googleapis / java-spanner Public
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: allows user-agent header with header provider #871
fix: allows user-agent header with header provider #871
Conversation
A bug was introduced, where if the caller tried to set a custom user agent with a header provider an exception would be thrown (for duplicate keys). Here, we merge the user agent set by the client along with the one set by the library, instead of throwing such exception.
Codecov Report
@@ Coverage Diff @@
## master #871 +/- ##
============================================
- Coverage 85.12% 85.10% -0.02%
- Complexity 2588 2590 +2
============================================
Files 143 143
Lines 14154 14156 +2
Branches 1366 1368 +2
============================================
- Hits 12048 12047 -1
- Misses 1537 1542 +5
+ Partials 569 567 -2
Continue to review full report at Codecov.
|
LGTM |
google-cloud-spanner/src/test/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpcTest.java
Show resolved
Hide resolved
Tests if the default user agent is present in the user-agent header set in the GapicSpannerRpc class.
@@ -494,6 +489,16 @@ public GapicSpannerRpc(final SpannerOptions options) { | |||
} | |||
} | |||
|
|||
private static HeaderProvider headerProviderWithUserAgentFrom(HeaderProvider headerProvider) { | |||
final Map<String, String> headersWithUserAgent = new HashMap<>(headerProvider.getHeaders()); | |||
final String userAgent = headersWithUserAgent.get(USER_AGENT_KEY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thiagotnunes user-agent
and User-Agent
should be equivalent.
This needs case insensitivity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bug was introduced, where if the caller tried to set a custom user agent with a header provider an exception would be thrown (for duplicate keys). Here, we merge the user agent set by the client along with the one set by the library, instead of throwing such exception.
Fixes #880