Yes, it does if the field is not provided. In connection.rb:
body = datum[:body].is_a?(String) ? StringIO.new(datum[:body]) : datum[:body]
# The HTTP spec isn't clear on it, but specifically, GET requests don't usually send bodies;
# if they don't, sending Content-Length:0 can cause issues.
unless datum[:method].to_s.casecmp('GET') == 0 && body.nil?
unless datum[:headers].has_key?('Content-Length')
datum[:headers]['Content-Length'] = detect_content_length(body)
end
end
def detect_content_length(body)
if body.respond_to?(:size)
# IO object: File, Tempfile, StringIO, etc.
body.size
elsif body.respond_to?(:stat)
# for 1.8.7 where file does not have size
body.stat.size
else
0
end
end
Since we need to record that field in the log, it doesn’t matter.
But it’s worthwhile to build a module for the job and redeliver action. 1) Reuse the code. 2) Easier to replace Excon.