Skip to content

storage(feat): Add accept encoding gzip for media operation only#26530

Open
shubhangi-google wants to merge 7 commits into
googleapis:mainfrom
shubhangi-google:add_accept_encoding_gzip_for_media_operation_only
Open

storage(feat): Add accept encoding gzip for media operation only#26530
shubhangi-google wants to merge 7 commits into
googleapis:mainfrom
shubhangi-google:add_accept_encoding_gzip_for_media_operation_only

Conversation

@shubhangi-google
Copy link
Copy Markdown
Contributor

This pull request adds the Accept-Encoding: gzip header to storage upload and download commands and includes corresponding unit tests.

Associated Storage library Pr: googleapis/google-cloud-ruby#33896

@shubhangi-google shubhangi-google requested a review from a team as a code owner May 19, 2026 06:56
@shubhangi-google shubhangi-google changed the title Add accept encoding gzip for media operation only storage(feat): Add accept encoding gzip for media operation only May 19, 2026
@@ -421,6 +421,10 @@ def make_storage_upload_command(method, path, options)
template = Addressable::Template.new(root_url + upload_path + path)
command = StorageUploadCommand.new(method, template, client_version: client_version)
command.options = request_options.merge(options)
command.options.header = command.options.header&.dup || {}
unless command.options.header.any? { |k, _| k.to_s.casecmp('accept-encoding') == 0 }
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.

Why are we doing this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we are checking if the accept-encoding header already exists if not then we will add it
(casecmp is being used to check the header with respect to case senstivity)

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.

header is a hashmap, right? Can't we directly check header['accept-encoding] ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, header is a hash, but it's a standard Ruby Hash where keys are case-sensitive. Because HTTP header names are case-insensitive, a user might have already provided it as 'Accept-Encoding' or 'ACCEPT-ENCODING'.

If we used header['accept-encoding'] directly, it would return nil if the casing didn't match exactly. Using any? with casecmp ensures we detect the header regardless of how the user cased it, so we don't add a duplicate.

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.

2 participants