lib/httpx/request.rb in httpx-0.22.5 vs lib/httpx/request.rb in httpx-0.23.0

- old
+ new

@@ -17,11 +17,15 @@ attr_reader :drain_error def_delegator :@body, :empty? def initialize(verb, uri, options = {}) - @verb = verb.to_s.downcase.to_sym + if verb.is_a?(Symbol) + warn "DEPRECATION WARNING: Using symbols for `verb` is deprecated, and will not be supported in httpx 1.0. " \ + "Use \"#{verb.to_s.upcase}\" instead." + end + @verb = verb.to_s.upcase @options = Options.new(options) @uri = Utils.to_uri(uri) if @uri.relative? origin = @options.origin raise(Error, "invalid URI: #{@uri}") unless origin @@ -114,11 +118,11 @@ def query return @query if defined?(@query) query = [] if (q = @options.params) - query << Transcoder.registry("form").encode(q) + query << Transcoder::Form.encode(q) end query << @uri.query if @uri.query @query = query.join("&") end @@ -136,11 +140,11 @@ end # :nocov: def inspect "#<HTTPX::Request:#{object_id} " \ - "#{@verb.to_s.upcase} " \ + "#{@verb} " \ "#{uri} " \ "@headers=#{@headers} " \ "@body=#{@body}>" end # :nocov: @@ -154,19 +158,11 @@ end end def initialize(headers, options) @headers = headers - @body = if options.body - Transcoder.registry("body").encode(options.body) - elsif options.form - Transcoder.registry("form").encode(options.form) - elsif options.json - Transcoder.registry("json").encode(options.json) - elsif options.xml - Transcoder.registry("xml").encode(options.xml) - end + @body = initialize_body(options) return if @body.nil? @headers["content-type"] ||= @body.content_type @headers["content-length"] = @body.bytesize unless unbounded_body? super(@body) @@ -205,11 +201,11 @@ @body.bytesize end def stream(body) encoded = body - encoded = Transcoder.registry("chunker").encode(body.enum_for(:each)) if chunked? + encoded = Transcoder::Chunker.encode(body.enum_for(:each)) if chunked? encoded end def unbounded_body? return @unbounded_body if defined?(@unbounded_body) @@ -229,9 +225,23 @@ def inspect "#<HTTPX::Request::Body:#{object_id} " \ "#{unbounded_body? ? "stream" : "@bytesize=#{bytesize}"}>" end # :nocov: + + private + + def initialize_body(options) + if options.body + Transcoder::Body.encode(options.body) + elsif options.form + Transcoder::Form.encode(options.form) + elsif options.json + Transcoder::JSON.encode(options.json) + elsif options.xml + Transcoder::Xml.encode(options.xml) + end + end end def transition(nextstate) case nextstate when :idle