From f82a200f7898687d81fd364d113f2887d0f6b28a Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 8 May 2026 11:04:44 +0000 Subject: [PATCH 1/7] adding header for storage_upload and storage_download --- .../lib/google/apis/core/base_service.rb | 3 ++- .../spec/google/apis/core/service_spec.rb | 22 +++++++++++++++++++ .../google/apis/core/storage_download_spec.rb | 7 ++++++ .../google/apis/core/storage_upload_spec.rb | 7 ++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/google-apis-core/lib/google/apis/core/base_service.rb b/google-apis-core/lib/google/apis/core/base_service.rb index 38723fc4d07..4063edd1cf8 100644 --- a/google-apis-core/lib/google/apis/core/base_service.rb +++ b/google-apis-core/lib/google/apis/core/base_service.rb @@ -262,7 +262,6 @@ def batch_upload(options = nil) end batch_command.execute(client) end - # Get the current HTTP connection # @return [Faraday::Connection] def client @@ -420,6 +419,7 @@ def make_storage_upload_command(method, path, options) verify_universe_domain! template = Addressable::Template.new(root_url + upload_path + path) command = StorageUploadCommand.new(method, template, client_version: client_version) + command.header["Accept-Encoding"] ||= "gzip" command.options = request_options.merge(options) apply_command_defaults(command) command @@ -458,6 +458,7 @@ def make_storage_download_command(method, path, options) verify_universe_domain! template = Addressable::Template.new(root_url + base_path + path) command = StorageDownloadCommand.new(method, template, client_version: client_version) + command.header["Accept-Encoding"] ||= "gzip" command.options = request_options.merge(options) command.query['alt'] = 'media' apply_command_defaults(command) diff --git a/google-apis-core/spec/google/apis/core/service_spec.rb b/google-apis-core/spec/google/apis/core/service_spec.rb index a4403f6cc3f..4c308061bdc 100644 --- a/google-apis-core/spec/google/apis/core/service_spec.rb +++ b/google-apis-core/spec/google/apis/core/service_spec.rb @@ -140,6 +140,10 @@ end.to raise_error(Google::Apis::UniverseDomainError) end + it 'should not include Accept-Encoding header' do + expect(command.header['Accept-Encoding']).to be_nil + end + include_examples 'with options' end @@ -173,6 +177,10 @@ expect(command.query).to include('alt' => 'media') end + it 'should not include Accept-Encoding header' do + expect(command.header['Accept-Encoding']).to_not eq('gzip') + end + include_examples 'with options' end @@ -192,6 +200,10 @@ expect(command.query).to include('alt' => 'media') end + it 'should include Accept-Encoding header' do + expect(command.header['Accept-Encoding']).to eq('gzip') + end + include_examples 'with options' end @@ -207,6 +219,10 @@ expect(url).to eql 'https://www.googleapis.com/upload/zoo/animals' end + it 'should not include Accept-Encoding header' do + expect(command.header['Accept-Encoding']).to be_nil + end + include_examples 'with options' end @@ -222,6 +238,10 @@ expect(url).to eql 'https://www.googleapis.com/upload/zoo/animals' end + it 'should include Accept-Encoding header' do + expect(command.header['Accept-Encoding']).to eq('gzip') + end + include_examples 'with options' end @@ -263,6 +283,7 @@ command expect(a_request(:put, upload_url)).to have_been_made.twice end + end context 'not restart resumable upload if upload is completed' do before(:example) do @@ -429,6 +450,7 @@ Content-Transfer-Encoding: binary POST /upload/zoo/animals\\? HTTP/1\\.1 +Accept-Encoding: gzip X-Goog-Api-Client: #{Regexp.escape(x_goog_api_client_value)} Content-Type: multipart/related; boundary=inner X-Goog-Upload-Protocol: multipart diff --git a/google-apis-core/spec/google/apis/core/storage_download_spec.rb b/google-apis-core/spec/google/apis/core/storage_download_spec.rb index 2e28587a781..e3f7cb94796 100644 --- a/google-apis-core/spec/google/apis/core/storage_download_spec.rb +++ b/google-apis-core/spec/google/apis/core/storage_download_spec.rb @@ -42,6 +42,13 @@ ).to have_been_made end + it 'should include a accept-encoding header' do + command.execute(client) + expect(a_request(:get, 'https://www.googleapis.com/zoo/animals') + .with { |req| req.headers.key?('Accept-Encoding') } + ).to have_been_made + end + it 'should receive content' do expect(received).to eql 'Hello world' end diff --git a/google-apis-core/spec/google/apis/core/storage_upload_spec.rb b/google-apis-core/spec/google/apis/core/storage_upload_spec.rb index 550ba987d3b..6246b0f0cc0 100644 --- a/google-apis-core/spec/google/apis/core/storage_upload_spec.rb +++ b/google-apis-core/spec/google/apis/core/storage_upload_spec.rb @@ -68,6 +68,13 @@ expect(a_request(:put, 'https://www.googleapis.com/zoo/animals') .with(body: 'Hello world')).to have_been_made end + + it 'should include an accept-encoding header' do + command.execute(client) + expect(a_request(:put, 'https://www.googleapis.com/zoo/animals') + .with { |req| req.headers['Accept-Encoding'] = 'gzip' } + ).to have_been_made + end end context('with StringIO input') do From 9344f306aba1d3b4b2e17e079c21f37a168d835b Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 8 May 2026 11:08:44 +0000 Subject: [PATCH 2/7] udo unwanted change --- google-apis-core/lib/google/apis/core/base_service.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/google-apis-core/lib/google/apis/core/base_service.rb b/google-apis-core/lib/google/apis/core/base_service.rb index 4063edd1cf8..a7ee1dea3f1 100644 --- a/google-apis-core/lib/google/apis/core/base_service.rb +++ b/google-apis-core/lib/google/apis/core/base_service.rb @@ -262,6 +262,7 @@ def batch_upload(options = nil) end batch_command.execute(client) end + # Get the current HTTP connection # @return [Faraday::Connection] def client From 33c3e42a80406ff7764e615c446c8158b4ba95be Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 8 May 2026 11:09:55 +0000 Subject: [PATCH 3/7] undo --- google-apis-core/lib/google/apis/core/base_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-apis-core/lib/google/apis/core/base_service.rb b/google-apis-core/lib/google/apis/core/base_service.rb index a7ee1dea3f1..c12898550bc 100644 --- a/google-apis-core/lib/google/apis/core/base_service.rb +++ b/google-apis-core/lib/google/apis/core/base_service.rb @@ -262,7 +262,7 @@ def batch_upload(options = nil) end batch_command.execute(client) end - + # Get the current HTTP connection # @return [Faraday::Connection] def client From 8b6b896c055a6652258eb1a3eaaa34b9022107b0 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 19 May 2026 04:45:01 +0000 Subject: [PATCH 4/7] adding header as optional header --- .../lib/google/apis/core/base_service.rb | 6 ++-- .../spec/google/apis/core/service_spec.rb | 35 ++++++++++++------- .../google/apis/core/storage_download_spec.rb | 5 ++- .../google/apis/core/storage_upload_spec.rb | 5 ++- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/google-apis-core/lib/google/apis/core/base_service.rb b/google-apis-core/lib/google/apis/core/base_service.rb index c12898550bc..8d8aca89edb 100644 --- a/google-apis-core/lib/google/apis/core/base_service.rb +++ b/google-apis-core/lib/google/apis/core/base_service.rb @@ -420,8 +420,9 @@ def make_storage_upload_command(method, path, options) verify_universe_domain! template = Addressable::Template.new(root_url + upload_path + path) command = StorageUploadCommand.new(method, template, client_version: client_version) - command.header["Accept-Encoding"] ||= "gzip" command.options = request_options.merge(options) + command.options.header = command.options.header&.dup || {} + command.options.header['Accept-Encoding'] ||= 'gzip' apply_command_defaults(command) command end @@ -459,8 +460,9 @@ def make_storage_download_command(method, path, options) verify_universe_domain! template = Addressable::Template.new(root_url + base_path + path) command = StorageDownloadCommand.new(method, template, client_version: client_version) - command.header["Accept-Encoding"] ||= "gzip" command.options = request_options.merge(options) + command.options.header = command.options.header&.dup || {} + command.options.header['Accept-Encoding'] ||= 'gzip' command.query['alt'] = 'media' apply_command_defaults(command) command diff --git a/google-apis-core/spec/google/apis/core/service_spec.rb b/google-apis-core/spec/google/apis/core/service_spec.rb index 4c308061bdc..ad88f19e3a6 100644 --- a/google-apis-core/spec/google/apis/core/service_spec.rb +++ b/google-apis-core/spec/google/apis/core/service_spec.rb @@ -187,21 +187,21 @@ context 'when making storage download commands' do let(:command) { service.send(:make_storage_download_command, :get, 'zoo/animals', authorization: 'foo') } - it 'should return the correct command type' do - expect(command).to be_an_instance_of(Google::Apis::Core::StorageDownloadCommand) - end + # it 'should return the correct command type' do + # expect(command).to be_an_instance_of(Google::Apis::Core::StorageDownloadCommand) + # end - it 'should build a correct URL' do - url = command.url.expand({}).to_s - expect(url).to eql 'https://www.googleapis.com/zoo/animals' - end + # it 'should build a correct URL' do + # url = command.url.expand({}).to_s + # expect(url).to eql 'https://www.googleapis.com/zoo/animals' + # end - it 'should include alt=media in params' do - expect(command.query).to include('alt' => 'media') - end + # it 'should include alt=media in params' do + # expect(command.query).to include('alt' => 'media') + # end it 'should include Accept-Encoding header' do - expect(command.header['Accept-Encoding']).to eq('gzip') + expect(command.options.header['Accept-Encoding']).to eq('gzip') end include_examples 'with options' @@ -239,7 +239,7 @@ end it 'should include Accept-Encoding header' do - expect(command.header['Accept-Encoding']).to eq('gzip') + expect(command.options.header['Accept-Encoding']).to eq('gzip') end include_examples 'with options' @@ -284,6 +284,11 @@ expect(a_request(:put, upload_url)).to have_been_made.twice end + it 'should include an accept-encoding header' do + command + expect(a_request(:put, upload_url).with { |req| req.headers['Accept-Encoding'] == 'gzip' }).to have_been_made.twice + end + end context 'not restart resumable upload if upload is completed' do before(:example) do @@ -307,6 +312,11 @@ command expect(a_request(:put, upload_url)).to have_been_made end + + it 'should include an accept-encoding header' do + command + expect(a_request(:put, upload_url).with { |req| req.headers['Accept-Encoding'] == 'gzip' }).to have_been_made + end end end @@ -450,7 +460,6 @@ Content-Transfer-Encoding: binary POST /upload/zoo/animals\\? HTTP/1\\.1 -Accept-Encoding: gzip X-Goog-Api-Client: #{Regexp.escape(x_goog_api_client_value)} Content-Type: multipart/related; boundary=inner X-Goog-Upload-Protocol: multipart diff --git a/google-apis-core/spec/google/apis/core/storage_download_spec.rb b/google-apis-core/spec/google/apis/core/storage_download_spec.rb index e3f7cb94796..c60f17da16d 100644 --- a/google-apis-core/spec/google/apis/core/storage_download_spec.rb +++ b/google-apis-core/spec/google/apis/core/storage_download_spec.rb @@ -42,11 +42,10 @@ ).to have_been_made end - it 'should include a accept-encoding header' do + it 'should include an Accept-Encoding header for media downloads' do command.execute(client) expect(a_request(:get, 'https://www.googleapis.com/zoo/animals') - .with { |req| req.headers.key?('Accept-Encoding') } - ).to have_been_made + .with { |req| req.headers['Accept-Encoding'].include?('gzip') }).to have_been_made end it 'should receive content' do diff --git a/google-apis-core/spec/google/apis/core/storage_upload_spec.rb b/google-apis-core/spec/google/apis/core/storage_upload_spec.rb index 6246b0f0cc0..ad5e8192665 100644 --- a/google-apis-core/spec/google/apis/core/storage_upload_spec.rb +++ b/google-apis-core/spec/google/apis/core/storage_upload_spec.rb @@ -69,11 +69,10 @@ .with(body: 'Hello world')).to have_been_made end - it 'should include an accept-encoding header' do + it 'should include an Accept-Encoding header in the outgoing request' do command.execute(client) expect(a_request(:put, 'https://www.googleapis.com/zoo/animals') - .with { |req| req.headers['Accept-Encoding'] = 'gzip' } - ).to have_been_made + .with { |req| req.headers['Accept-Encoding'].include?('gzip') }).to have_been_made end end From 751d8c3d6f495ad779cb4cdbeca3cadd456204b0 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 19 May 2026 04:49:55 +0000 Subject: [PATCH 5/7] adding --- .../spec/google/apis/core/service_spec.rb | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/google-apis-core/spec/google/apis/core/service_spec.rb b/google-apis-core/spec/google/apis/core/service_spec.rb index ad88f19e3a6..d20dab3d0c6 100644 --- a/google-apis-core/spec/google/apis/core/service_spec.rb +++ b/google-apis-core/spec/google/apis/core/service_spec.rb @@ -187,18 +187,18 @@ context 'when making storage download commands' do let(:command) { service.send(:make_storage_download_command, :get, 'zoo/animals', authorization: 'foo') } - # it 'should return the correct command type' do - # expect(command).to be_an_instance_of(Google::Apis::Core::StorageDownloadCommand) - # end - - # it 'should build a correct URL' do - # url = command.url.expand({}).to_s - # expect(url).to eql 'https://www.googleapis.com/zoo/animals' - # end - - # it 'should include alt=media in params' do - # expect(command.query).to include('alt' => 'media') - # end + it 'should return the correct command type' do + expect(command).to be_an_instance_of(Google::Apis::Core::StorageDownloadCommand) + end + + it 'should build a correct URL' do + url = command.url.expand({}).to_s + expect(url).to eql 'https://www.googleapis.com/zoo/animals' + end + + it 'should include alt=media in params' do + expect(command.query).to include('alt' => 'media') + end it 'should include Accept-Encoding header' do expect(command.options.header['Accept-Encoding']).to eq('gzip') From 182f1ef4abcb51afcf337aeccbae79b9750da7d2 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 19 May 2026 04:52:48 +0000 Subject: [PATCH 6/7] adding --- google-apis-core/spec/google/apis/core/service_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-apis-core/spec/google/apis/core/service_spec.rb b/google-apis-core/spec/google/apis/core/service_spec.rb index d20dab3d0c6..c4e2d6851df 100644 --- a/google-apis-core/spec/google/apis/core/service_spec.rb +++ b/google-apis-core/spec/google/apis/core/service_spec.rb @@ -178,7 +178,7 @@ end it 'should not include Accept-Encoding header' do - expect(command.header['Accept-Encoding']).to_not eq('gzip') + expect(command.options.header['Accept-Encoding']).to be_nil end include_examples 'with options' @@ -220,7 +220,7 @@ end it 'should not include Accept-Encoding header' do - expect(command.header['Accept-Encoding']).to be_nil + expect(command.options.header['Accept-Encoding']).to be_nil end include_examples 'with options' From 1d3bee1712b34d68a04d8b07cb762b326bebb3b4 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 19 May 2026 05:30:22 +0000 Subject: [PATCH 7/7] refactor --- google-apis-core/lib/google/apis/core/base_service.rb | 8 ++++++-- google-apis-core/spec/google/apis/core/service_spec.rb | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/google-apis-core/lib/google/apis/core/base_service.rb b/google-apis-core/lib/google/apis/core/base_service.rb index 8d8aca89edb..61fc3f9df5f 100644 --- a/google-apis-core/lib/google/apis/core/base_service.rb +++ b/google-apis-core/lib/google/apis/core/base_service.rb @@ -422,7 +422,9 @@ def make_storage_upload_command(method, path, options) command = StorageUploadCommand.new(method, template, client_version: client_version) command.options = request_options.merge(options) command.options.header = command.options.header&.dup || {} - command.options.header['Accept-Encoding'] ||= 'gzip' + unless command.options.header.any? { |k, _| k.to_s.casecmp('accept-encoding') == 0 } + command.options.header['Accept-Encoding'] = 'gzip' + end apply_command_defaults(command) command end @@ -462,7 +464,9 @@ def make_storage_download_command(method, path, options) command = StorageDownloadCommand.new(method, template, client_version: client_version) command.options = request_options.merge(options) command.options.header = command.options.header&.dup || {} - command.options.header['Accept-Encoding'] ||= 'gzip' + unless command.options.header.any? { |k, _| k.to_s.casecmp('accept-encoding') == 0 } + command.options.header['Accept-Encoding'] = 'gzip' + end command.query['alt'] = 'media' apply_command_defaults(command) command diff --git a/google-apis-core/spec/google/apis/core/service_spec.rb b/google-apis-core/spec/google/apis/core/service_spec.rb index c4e2d6851df..6892d3de16f 100644 --- a/google-apis-core/spec/google/apis/core/service_spec.rb +++ b/google-apis-core/spec/google/apis/core/service_spec.rb @@ -141,7 +141,7 @@ end it 'should not include Accept-Encoding header' do - expect(command.header['Accept-Encoding']).to be_nil + expect(command.options.header&.[]('Accept-Encoding')).to be_nil end include_examples 'with options' @@ -178,7 +178,7 @@ end it 'should not include Accept-Encoding header' do - expect(command.options.header['Accept-Encoding']).to be_nil + expect(command.options.header&.[]('Accept-Encoding')).to be_nil end include_examples 'with options' @@ -220,7 +220,7 @@ end it 'should not include Accept-Encoding header' do - expect(command.options.header['Accept-Encoding']).to be_nil + expect(command.options.header&.[]('Accept-Encoding')).to be_nil end include_examples 'with options'