Skip to content

Commit

Permalink
chore: Improve implicit Content-Length failures
Browse files Browse the repository at this point in the history
Suggest setting `Content-Length` header manually in case we can't guess
body size.

See-Also: #560
  • Loading branch information
ixti committed Sep 14, 2021
1 parent 297d303 commit 00bc96a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/http/request/body.rb
Expand Up @@ -17,14 +17,13 @@ def initialize(source)
def size
if @source.is_a?(String)
@source.bytesize
elsif @source.respond_to?(:read)
raise RequestError, "IO object must respond to #size" unless @source.respond_to?(:size)

elsif @source.respond_to?(:read) && @source.respond_to?(:size)
@source.size
elsif @source.nil?
0
else
raise RequestError, "cannot determine size of body: #{@source.inspect}"
raise RequestError, "cannot determine size of body: #{@source.inspect}, " \
"please set 'Content-Length' header explicitly"
end
end

Expand Down

0 comments on commit 00bc96a

Please sign in to comment.