class HTTPX::Request

  1. lib/httpx/request.rb
Superclass: Object

Included modules

  1. Callbacks

Constants

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}"  

Attributes

body [R]
headers [R]
options [R]
response [R]
state [R]
uri [R]
verb [R]

Public Class methods

new (verb, uri, options = {})
[show source]
   # File lib/httpx/request.rb
46 def initialize(verb, uri, options = {})
47   @verb    = verb.to_s.downcase.to_sym
48   @uri     = URI(uri.to_s)
49   @options = Options.new(options)
50 
51   raise(Error, "unknown method: #{verb}") unless METHODS.include?(@verb)
52 
53   @headers = @options.headers_class.new(@options.headers)
54   @headers["user-agent"] ||= USER_AGENT
55   @headers["accept"]     ||= "*/*"
56 
57   @body = @options.request_body_class.new(@headers, @options)
58   @state = :idle
59 end

Public Instance methods

authority ()
[show source]
   # File lib/httpx/request.rb
95 def authority
96   @uri.authority
97 end
drain_body ()
[show source]
    # File lib/httpx/request.rb
115 def drain_body
116   return nil if @body.nil?
117 
118   @drainer ||= @body.each
119   chunk = @drainer.next
120   chunk.dup
121 rescue StopIteration
122   nil
123 end
expects? ()
[show source]
    # File lib/httpx/request.rb
249 def expects?
250   @headers["expect"] == "100-continue" &&
251     @response && @response.status == 100
252 end
initialize_with_escape (verb, uri, options = {})

rubocop: disable Lint/UriEscapeUnescape:

[show source]
   # File lib/httpx/request.rb
64 def initialize_with_escape(verb, uri, options = {})
65   initialize_without_escape(verb, URI.escape(uri.to_s), options)
66 end
inspect ()

:nocov:

[show source]
    # File lib/httpx/request.rb
126 def inspect
127   "#<HTTPX::Request:#{object_id} " \
128   "#{@verb.to_s.upcase} " \
129   "#{uri} " \
130   "@headers=#{@headers} " \
131   "@body=#{@body}>"
132 end
merge_headers (h)

:nocov:

[show source]
   # File lib/httpx/request.rb
73 def merge_headers(h)
74   @headers = @headers.merge(h)
75 end
origin ()
[show source]
    # File lib/httpx/request.rb
100 def origin
101   @uri.origin
102 end
path ()
[show source]
   # File lib/httpx/request.rb
87 def path
88   path = uri.path.dup
89   path << "/" if path.empty?
90   path << "?#{query}" unless query.empty?
91   path
92 end
query ()
[show source]
    # File lib/httpx/request.rb
104 def query
105   return @query if defined?(@query)
106 
107   query = []
108   if (q = @options.params)
109     query << URI.encode_www_form(q)
110   end
111   query << @uri.query if @uri.query
112   @query = query.join("&")
113 end
response= (response)
[show source]
   # File lib/httpx/request.rb
81 def response=(response)
82   return unless response
83 
84   @response = response
85 end
scheme ()
[show source]
   # File lib/httpx/request.rb
77 def scheme
78   @uri.scheme
79 end
transition (nextstate)
[show source]
    # File lib/httpx/request.rb
218 def transition(nextstate)
219   case nextstate
220   when :idle
221     @response = nil
222     @drainer = nil
223   when :headers
224     return unless @state == :idle
225   when :body
226     return unless @state == :headers ||
227                   @state == :expect
228 
229     if @headers.key?("expect")
230       unless @response
231         @state = :expect
232         return
233       end
234 
235       case @response.status
236       when 100
237         # deallocate
238         @response = nil
239       end
240     end
241   when :done
242     return if @state == :expect
243   end
244   @state = nextstate
245   emit(@state)
246   nil
247 end