Class: HTTPX::Request
- Inherits:
-
Object
- Object
- HTTPX::Request
- Extended by:
- Forwardable
- Includes:
- Callbacks
- Defined in:
- lib/httpx/request.rb
Direct Known Subclasses
Defined Under Namespace
Constant Summary collapse
- 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}"
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#response ⇒ Object
Returns the value of attribute response.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Instance Method Summary collapse
- #authority ⇒ Object
- #drain_body ⇒ Object
- #expects? ⇒ Boolean
-
#initialize_with_escape(verb, uri, options = {}) ⇒ Object
(also: #initialize)
rubocop: disable Lint/UriEscapeUnescape:.
-
#inspect ⇒ Object
:nocov:.
- #interests ⇒ Object
-
#merge_headers(h) ⇒ Object
:nocov:.
- #origin ⇒ Object
- #path ⇒ Object
- #query ⇒ Object
- #scheme ⇒ Object
- #transition(nextstate) ⇒ Object
Methods included from Callbacks
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
36 37 38 |
# File 'lib/httpx/request.rb', line 36 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
36 37 38 |
# File 'lib/httpx/request.rb', line 36 def headers @headers end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
38 39 40 |
# File 'lib/httpx/request.rb', line 38 def @options end |
#response ⇒ Object
Returns the value of attribute response.
38 39 40 |
# File 'lib/httpx/request.rb', line 38 def response @response end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
36 37 38 |
# File 'lib/httpx/request.rb', line 36 def state @state end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
36 37 38 |
# File 'lib/httpx/request.rb', line 36 def uri @uri end |
#verb ⇒ Object (readonly)
Returns the value of attribute verb.
36 37 38 |
# File 'lib/httpx/request.rb', line 36 def verb @verb end |
Instance Method Details
#authority ⇒ Object
101 102 103 |
# File 'lib/httpx/request.rb', line 101 def @uri. end |
#drain_body ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/httpx/request.rb', line 121 def drain_body return nil if @body.nil? @drainer ||= @body.each chunk = @drainer.next chunk.dup rescue StopIteration nil end |
#expects? ⇒ Boolean
255 256 257 258 |
# File 'lib/httpx/request.rb', line 255 def expects? @headers["expect"] == "100-continue" && @response && @response.status == 100 end |
#initialize_with_escape(verb, uri, options = {}) ⇒ Object Also known as: initialize
rubocop: disable Lint/UriEscapeUnescape:
70 71 72 |
# File 'lib/httpx/request.rb', line 70 def initialize_with_escape(verb, uri, = {}) initialize_without_escape(verb, URI.escape(uri.to_s), ) end |
#inspect ⇒ Object
:nocov:
132 133 134 135 136 137 138 |
# File 'lib/httpx/request.rb', line 132 def inspect "#<HTTPX::Request:#{object_id} " \ "#{@verb.to_s.upcase} " \ "#{uri} " \ "@headers=#{@headers} " \ "@body=#{@body}>" end |
#interests ⇒ Object
61 62 63 64 65 |
# File 'lib/httpx/request.rb', line 61 def interests return :r if @state == :done || @state == :expect :w end |
#merge_headers(h) ⇒ Object
:nocov:
79 80 81 |
# File 'lib/httpx/request.rb', line 79 def merge_headers(h) @headers = @headers.merge(h) end |
#origin ⇒ Object
106 107 108 |
# File 'lib/httpx/request.rb', line 106 def origin @uri.origin end |
#path ⇒ Object
93 94 95 96 97 98 |
# File 'lib/httpx/request.rb', line 93 def path path = uri.path.dup path << "/" if path.empty? path << "?#{query}" unless query.empty? path end |
#query ⇒ Object
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/httpx/request.rb', line 110 def query return @query if defined?(@query) query = [] if (q = @options.params) query << URI.encode_www_form(q) end query << @uri.query if @uri.query @query = query.join("&") end |
#scheme ⇒ Object
83 84 85 |
# File 'lib/httpx/request.rb', line 83 def scheme @uri.scheme end |
#transition(nextstate) ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/httpx/request.rb', line 224 def transition(nextstate) case nextstate when :idle @response = nil @drainer = nil when :headers return unless @state == :idle when :body return unless @state == :headers || @state == :expect if @headers.key?("expect") unless @response @state = :expect return end case @response.status when 100 # deallocate @response = nil end end when :done return if @state == :expect end @state = nextstate emit(@state) nil end |