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
Co-Authored-By: @savonarola <[email protected]>
ixti and savonarola committed Sep 14, 2021

Verified

This commit was signed with the committer’s verified signature. The key has expired.
ixti Alexey Zapparov
1 parent 297d303 commit c603521
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/http/request/body.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c603521

Please sign in to comment.