From c60352148295c248d716356fad274f4a5dce35d1 Mon Sep 17 00:00:00 2001 From: Alexey Zapparov Date: Tue, 14 Sep 2021 16:37:45 +0200 Subject: [PATCH] chore: Improve implicit Content-Length failures Suggest setting `Content-Length` header manually in case we can't guess body size. See-Also: https://github.com/httprb/http/pull/560 Co-Authored-By: @savonarola --- lib/http/request/body.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/http/request/body.rb b/lib/http/request/body.rb index 14af30b8..4e199450 100644 --- a/lib/http/request/body.rb +++ b/lib/http/request/body.rb @@ -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