feat: add new Options to allow per method header values#2941
Merged
BenWhitehead merged 4 commits intomainfrom Feb 25, 2025
Merged
feat: add new Options to allow per method header values#2941BenWhitehead merged 4 commits intomainfrom
BenWhitehead merged 4 commits intomainfrom
Conversation
Add new "Option"s for those methods which already have option types to allow providing an ImmutableMap<String, String> to be applied as extra headers to all requests sent as part of that operation. If an operation has multiple sources of input Options (rewrite) the "first" (i.e. source option) will be the one added to the request. The following resources do not have "Option"s and therefor do not have extra headers support at this time: * Acl * DefaultAcl * ServiceAccount * Notification
ddelgrosso1
reviewed
Feb 25, 2025
google-cloud-storage/src/main/java/com/google/cloud/storage/UnifiedOpts.java
Outdated
Show resolved
Hide resolved
ddelgrosso1
approved these changes
Feb 25, 2025
Contributor
ddelgrosso1
left a comment
There was a problem hiding this comment.
I'm not a java expert but LGTM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add new "Option"s for those methods which already have option types to allow providing an ImmutableMap<String, String> to be applied as extra headers to all requests sent as part of that operation.
If an operation has multiple sources of input Options (rewrite) the "first" (i.e. source option) will be the one added to the request.
The following resources do not have "Option"s and therefor do not have extra headers support at this time:
Overview of the changes
This blind number of lines is large, but the number of differences is actually fairly low.
HeadersOpt` in UnifiedOpts, this is the primary guts of the new feature and is responsible for holding onto the extra header values and validating the provided headers to ensure no collisions with headers otherwise set by our library/restricted by gcs.extraHeaders" to each of the 15 option classes along with accompanying javadocs. All javadocs are the exact same, and were copy-pasted for each method.Utils#headerNameToLowerCaseto centralize the logic for transforming header names across all locationsStorageRpc.Options#EXTRA_HEADERSto support extra headers for JSON callsHttpStorageRpc(433 lines),ApiaryUnbufferedReadableByteChannel(13 lines) andJsonResumable*(~45 lines + ~50 lines for existing tests) classes to takeEXTRA_HEADERSinto considerationITExtraHeadersOptionTestto validate headers are properly added to each request of various operationsAssertRequestHeaderswhich bothGrpcRequestAuditingandRequestAuditingnow implement -- this interface makes it easy for each transport to share common methods for asserting request headers