Repository navigation
Conversation
…rs when requested When SignUrlOption.withContentType() or withMd5() is used with V4 signing, include the corresponding headers in the signed headers, matching V2 behavior.
There was a problem hiding this comment.
Code Review
This pull request updates V4 URL signing in StorageImpl to correctly include content-type and content-md5 headers in the signed headers list when specified, while avoiding duplicates if they are already provided in the external headers. It also adds corresponding unit tests in StorageImplMockitoTest. The feedback suggests simplifying the retrieval of external headers from optionMap by using Map.getOrDefault instead of a ternary operator checking containsKey.
| Map<String, String> extHeaders = | ||
| optionMap.containsKey(SignUrlOption.Option.EXT_HEADERS) | ||
| ? (Map<String, String>) optionMap.get(SignUrlOption.Option.EXT_HEADERS) | ||
| : ImmutableMap.of(); |
There was a problem hiding this comment.
Instead of retrieving the extra headers map and performing an explicit null check, we can simplify the code by using Map.getOrDefault. This avoids redundant null-handling logic and leverages the map's built-in capabilities.
Map<String, String> extHeaders =
(Map<String, String>) optionMap.getOrDefault(SignUrlOption.Option.EXT_HEADERS, ImmutableMap.of());References
- Avoid adding redundant null or type checks before calling Map.getOrDefault if the underlying map implementation already safely handles null or incompatible keys.
When SignUrlOption.withContentType() or withMd5() is used with V4 signing, include the corresponding headers in the signed headers, matching V2 behavior.