def content_length_from options
data = options[:data]
case
when options[:content_length] then options[:content_length]
when options[:file] then File.size(options[:file])
when data.is_a?(Pathname) then File.size(data.to_s)
when data.is_a?(File) then File.size(data.path)
when data.respond_to?(:bytesize) then data.bytesize
when data.respond_to?(:size) then data.size
when data.respond_to?(:length) then data.length
else raise ArgumentError, 'content_length was not provided ' +
'and could not be determined'
end
end