Skip to content

fix(storage): include content-type and content-md5 in V4 signed headers - #15093

Open
Dhriti07 wants to merge 1 commit into
mainfrom
storage-v4-signed-headers
Open

Dhriti07 wants to merge 1 commit into
mainfrom
storage-v4-signed-headers

Conversation

@Dhriti07

Copy link
Copy Markdown
Contributor

When SignUrlOption.withContentType() or withMd5() is used with V4 signing, include the corresponding headers in the signed headers, matching V2 behavior.

…rs when requested

When SignUrlOption.withContentType() or withMd5() is used with V4 signing,
include the corresponding headers in the signed headers, matching V2 behavior.

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

Copy link
Copy Markdown
Contributor

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 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.

Comment on lines +1209 to +1212
Map<String, String> extHeaders =
optionMap.containsKey(SignUrlOption.Option.EXT_HEADERS)
? (Map<String, String>) optionMap.get(SignUrlOption.Option.EXT_HEADERS)
: ImmutableMap.of();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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
  1. Avoid adding redundant null or type checks before calling Map.getOrDefault if the underlying map implementation already safely handles null or incompatible keys.

@Dhriti07
Dhriti07 marked this pull request as ready for review November 20, 2026 09:12
@Dhriti07
Dhriti07 requested review from a team as code owners November 20, 2026 09:12

This branch has not been deployed

No deployments
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