lib/httpx/request.rb in httpx-0.9.0 vs lib/httpx/request.rb in httpx-0.10.0
- old
+ new
@@ -31,23 +31,19 @@
:search
].freeze
USER_AGENT = "httpx.rb/#{VERSION}"
- attr_reader :verb, :uri, :headers, :body, :state
+ attr_reader :verb, :uri, :headers, :body, :state, :options, :response
- attr_reader :options, :response
-
- def_delegator :@body, :<<
-
def_delegator :@body, :empty?
def_delegator :@body, :chunk!
def initialize(verb, uri, options = {})
@verb = verb.to_s.downcase.to_sym
- @uri = URI(uri.to_s)
+ @uri = Utils.uri(uri)
@options = Options.new(options)
raise(Error, "unknown method: #{verb}") unless METHODS.include?(@verb)
@headers = @options.headers_class.new(@options.headers)
@@ -62,21 +58,19 @@
return :r if @state == :done || @state == :expect
:w
end
- # :nocov:
if RUBY_VERSION < "2.2"
- # rubocop: disable Lint/UriEscapeUnescape:
+ URIParser = URI::DEFAULT_PARSER
+
def initialize_with_escape(verb, uri, options = {})
- initialize_without_escape(verb, URI.escape(uri.to_s), options)
+ initialize_without_escape(verb, URIParser.escape(uri.to_s), options)
end
alias_method :initialize_without_escape, :initialize
alias_method :initialize, :initialize_with_escape
- # rubocop: enable Lint/UriEscapeUnescape:
end
- # :nocov:
def merge_headers(h)
@headers = @headers.merge(h)
end
@@ -178,22 +172,16 @@
def empty?
return true if @body.nil?
return false if chunked?
- bytesize.zero?
+ @body.bytesize.zero?
end
def bytesize
return 0 if @body.nil?
- if @body.respond_to?(:bytesize)
- @body.bytesize
- elsif @body.respond_to?(:size)
- @body.size
- else
- raise Error, "cannot determine size of body: #{@body.inspect}"
- end
+ @body.bytesize
end
def stream(body)
encoded = body
encoded = Transcoder.registry("chunker").encode(body) if chunked?