lib/httpx/request.rb in httpx-0.20.5 vs lib/httpx/request.rb in httpx-0.21.0
- old
+ new
@@ -7,33 +7,10 @@
class Request
extend Forwardable
include Callbacks
using URIExtensions
- METHODS = [
- # RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1
- :options, :get, :head, :post, :put, :delete, :trace, :connect,
-
- # RFC 2518: HTTP Extensions for Distributed Authoring -- WEBDAV
- :propfind, :proppatch, :mkcol, :copy, :move, :lock, :unlock,
-
- # RFC 3648: WebDAV Ordered Collections Protocol
- :orderpatch,
-
- # RFC 3744: WebDAV Access Control Protocol
- :acl,
-
- # RFC 6352: vCard Extensions to WebDAV -- CardDAV
- :report,
-
- # RFC 5789: PATCH Method for HTTP
- :patch,
-
- # draft-reschke-webdav-search: WebDAV Search
- :search
- ].freeze
-
USER_AGENT = "httpx.rb/#{VERSION}"
attr_reader :verb, :uri, :headers, :body, :state, :options, :response
# Exception raised during enumerable body writes
@@ -52,20 +29,30 @@
base_path = @options.base_path
@uri = origin.merge("#{base_path}#{@uri}")
end
- raise(Error, "unknown method: #{verb}") unless METHODS.include?(@verb)
-
@headers = @options.headers_class.new(@options.headers)
@headers["user-agent"] ||= USER_AGENT
@headers["accept"] ||= "*/*"
@body = @options.request_body_class.new(@headers, @options)
@state = :idle
end
+ def read_timeout
+ @options.timeout[:read_timeout]
+ end
+
+ def write_timeout
+ @options.timeout[:write_timeout]
+ end
+
+ def request_timeout
+ @options.timeout[:request_timeout]
+ end
+
def trailers?
defined?(@trailers)
end
def trailers
@@ -106,10 +93,11 @@
@response = response
end
def path
path = uri.path.dup
+ path = +"" if path.nil?
path << "/" if path.empty?
path << "?#{query}" unless query.empty?
path
end
@@ -172,9 +160,11 @@
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
return if @body.nil?
@headers["content-type"] ||= @body.content_type
@headers["content-length"] = @body.bytesize unless unbounded_body?