class HTTPClient::Session

def read_body_length(&block)

def read_body_length(&block)
  return nil if @content_length == 0
  while true
    buf = empty_bin_str
    maxbytes = @read_block_size
    maxbytes = @content_length if maxbytes > @content_length && @content_length > 0
    ::Timeout.timeout(@receive_timeout, ReceiveTimeoutError) do
      begin
        @socket.readpartial(maxbytes, buf)
      rescue EOFError
        close
        buf = nil
        if @strict_response_size_check
          raise BadResponseError.new("EOF while reading rest #{@content_length} bytes")
        end
      end
    end
    if buf && buf.bytesize > 0
      @content_length -= buf.bytesize
      yield buf
    else
      @content_length = 0
    end
    return if @content_length == 0
  end
end