class HTTPX::Request

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

Included modules

  1. Callbacks

Constants

URIParser = URI::DEFAULT_PARSER  
USER_AGENT = "httpx.rb/#{VERSION}"  

Attributes

body [R]
drain_error [R]

Exception raised during enumerable body writes

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
21 def initialize(verb, uri, options = {})
22   if verb.is_a?(Symbol)
23     warn "DEPRECATION WARNING: Using symbols for `verb` is deprecated, and will not be supported in httpx 1.0. " \
24          "Use \"#{verb.to_s.upcase}\" instead."
25   end
26   @verb    = verb.to_s.upcase
27   @options = Options.new(options)
28   @uri     = Utils.to_uri(uri)
29   if @uri.relative?
30     origin = @options.origin
31     raise(Error, "invalid URI: #{@uri}") unless origin
32 
33     base_path = @options.base_path
34 
35     @uri = origin.merge("#{base_path}#{@uri}")
36   end
37 
38   @headers = @options.headers_class.new(@options.headers)
39   @headers["user-agent"] ||= USER_AGENT
40   @headers["accept"]     ||= "*/*"
41 
42   @body = @options.request_body_class.new(@headers, @options)
43   @state = :idle
44 end

Public Instance methods

authority()
[show source]
    # File lib/httpx/request.rb
109 def authority
110   @uri.authority
111 end
drain_body()
[show source]
    # File lib/httpx/request.rb
129 def drain_body
130   return nil if @body.nil?
131 
132   @drainer ||= @body.each
133   chunk = @drainer.next
134   chunk.dup
135 rescue StopIteration
136   nil
137 rescue StandardError => e
138   @drain_error = e
139   nil
140 end
expects?()
[show source]
    # File lib/httpx/request.rb
280 def expects?
281   @headers["expect"] == "100-continue" && @informational_status == 100 && !@response
282 end
initialize_with_escape(verb, uri, options = {})
[show source]
   # File lib/httpx/request.rb
75 def initialize_with_escape(verb, uri, options = {})
76   initialize_without_escape(verb, URIParser.escape(uri.to_s), options)
77 end
inspect()

:nocov:

[show source]
    # File lib/httpx/request.rb
143 def inspect
144   "#<HTTPX::Request:#{object_id} " \
145     "#{@verb} " \
146     "#{uri} " \
147     "@headers=#{@headers} " \
148     "@body=#{@body}>"
149 end
interests()
[show source]
   # File lib/httpx/request.rb
66 def interests
67   return :r if @state == :done || @state == :expect
68 
69   :w
70 end
merge_headers(h)
[show source]
   # File lib/httpx/request.rb
82 def merge_headers(h)
83   @headers = @headers.merge(h)
84 end
origin()
[show source]
    # File lib/httpx/request.rb
114 def origin
115   @uri.origin
116 end
path()
[show source]
    # File lib/httpx/request.rb
100 def path
101   path = uri.path.dup
102   path =  +"" if path.nil?
103   path << "/" if path.empty?
104   path << "?#{query}" unless query.empty?
105   path
106 end
query()
[show source]
    # File lib/httpx/request.rb
118 def query
119   return @query if defined?(@query)
120 
121   query = []
122   if (q = @options.params)
123     query << Transcoder::Form.encode(q)
124   end
125   query << @uri.query if @uri.query
126   @query = query.join("&")
127 end
read_timeout()
[show source]
   # File lib/httpx/request.rb
46 def read_timeout
47   @options.timeout[:read_timeout]
48 end
request_timeout()
[show source]
   # File lib/httpx/request.rb
54 def request_timeout
55   @options.timeout[:request_timeout]
56 end
response=(response)
[show source]
   # File lib/httpx/request.rb
90 def response=(response)
91   return unless response
92 
93   if response.is_a?(Response) && response.status == 100 && @headers.key?("expect")
94     @informational_status = response.status
95     return
96   end
97   @response = response
98 end
scheme()
[show source]
   # File lib/httpx/request.rb
86 def scheme
87   @uri.scheme
88 end
trailers()
[show source]
   # File lib/httpx/request.rb
62 def trailers
63   @trailers ||= @options.headers_class.new
64 end
trailers?()
[show source]
   # File lib/httpx/request.rb
58 def trailers?
59   defined?(@trailers)
60 end
transition(nextstate)
[show source]
    # File lib/httpx/request.rb
246 def transition(nextstate)
247   case nextstate
248   when :idle
249     @body.rewind
250     @response = nil
251     @drainer = nil
252   when :headers
253     return unless @state == :idle
254   when :body
255     return unless @state == :headers ||
256                   @state == :expect
257 
258     if @headers.key?("expect")
259       if @informational_status && @informational_status == 100
260         # check for 100 Continue response, and deallocate the var
261         # if @informational_status == 100
262         #   @response = nil
263         # end
264       else
265         return if @state == :expect # do not re-set it
266 
267         nextstate = :expect
268       end
269     end
270   when :trailers
271     return unless @state == :body
272   when :done
273     return if @state == :expect
274   end
275   @state = nextstate
276   emit(@state, self)
277   nil
278 end
write_timeout()
[show source]
   # File lib/httpx/request.rb
50 def write_timeout
51   @options.timeout[:write_timeout]
52 end