storage(feat): Add accept encoding gzip for media operation only#26530
storage(feat): Add accept encoding gzip for media operation only#26530shubhangi-google wants to merge 7 commits into
Conversation
| @@ -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 } | |||
There was a problem hiding this comment.
Why are we doing this?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
header is a hashmap, right? Can't we directly check header['accept-encoding] ?
There was a problem hiding this comment.
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.
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