From 9d56de8b9258b54366872a53506c2d3ecea30885 Mon Sep 17 00:00:00 2001 From: Daniel Azuma Date: Wed, 6 Aug 2025 22:48:07 +0000 Subject: [PATCH] fix(core): Compute and send content-length header when posting a CompositeIO --- google-apis-core/lib/google/apis/core/http_command.rb | 3 +++ google-apis-core/spec/google/apis/core/batch_spec.rb | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/google-apis-core/lib/google/apis/core/http_command.rb b/google-apis-core/lib/google/apis/core/http_command.rb index f5b935d64d6..f07a323b9e5 100644 --- a/google-apis-core/lib/google/apis/core/http_command.rb +++ b/google-apis-core/lib/google/apis/core/http_command.rb @@ -183,6 +183,9 @@ def prepare! end self.body = '' if self.body.nil? && [:post, :put, :patch].include?(method) + if defined?(::Google::Apis::Core::CompositeIO) && body.is_a?(::Google::Apis::Core::CompositeIO) + header["Content-Length"] ||= body.size.to_s + end end # Release any resources used by this command diff --git a/google-apis-core/spec/google/apis/core/batch_spec.rb b/google-apis-core/spec/google/apis/core/batch_spec.rb index 5ba759325d3..7becd7e0032 100644 --- a/google-apis-core/spec/google/apis/core/batch_spec.rb +++ b/google-apis-core/spec/google/apis/core/batch_spec.rb @@ -118,7 +118,10 @@ --123abc-- EOF - expect(a_request(:post, 'https://www.googleapis.com/batch').with(body: expected_body)).to have_been_made + expect( + a_request(:post, 'https://www.googleapis.com/batch') + .with(body: expected_body, headers: {"Content-Length" => expected_body.size.to_s}) + ).to have_been_made end it 'should send content with authorization header when set' do