Skip to content

Commit e817c6f

Browse files
authored
fix(core): Compute and send content-length header when posting a CompositeIO (#23864)
1 parent e300f9d commit e817c6f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

google-apis-core/lib/google/apis/core/http_command.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ def prepare!
183183
end
184184

185185
self.body = '' if self.body.nil? && [:post, :put, :patch].include?(method)
186+
if defined?(::Google::Apis::Core::CompositeIO) && body.is_a?(::Google::Apis::Core::CompositeIO)
187+
header["Content-Length"] ||= body.size.to_s
188+
end
186189
end
187190

188191
# Release any resources used by this command

google-apis-core/spec/google/apis/core/batch_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@
118118
--123abc--
119119
120120
EOF
121-
expect(a_request(:post, 'https://www.googleapis.com/batch').with(body: expected_body)).to have_been_made
121+
expect(
122+
a_request(:post, 'https://www.googleapis.com/batch')
123+
.with(body: expected_body, headers: {"Content-Length" => expected_body.size.to_s})
124+
).to have_been_made
122125
end
123126

124127
it 'should send content with authorization header when set' do

0 commit comments

Comments
 (0)