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   @verb    = verb.to_s.downcase.to_sym
23   @options = Options.new(options)
24   @uri     = Utils.to_uri(uri)
25   if @uri.relative?
26     origin = @options.origin
27     raise(Error, "invalid URI: #{@uri}") unless origin
28 
29     base_path = @options.base_path
30 
31     @uri = origin.merge("#{base_path}#{@uri}")
32   end
33 
34   @headers = @options.headers_class.new(@options.headers)
35   @headers["user-agent"] ||= USER_AGENT
36   @headers["accept"]     ||= "*/*"
37 
38   @body = @options.request_body_class.new(@headers, @options)
39   @state = :idle
40 end

Public Instance methods

authority()
[show source]
    # File lib/httpx/request.rb
105 def authority
106   @uri.authority
107 end
drain_body()
[show source]
    # File lib/httpx/request.rb
125 def drain_body
126   return nil if @body.nil?
127 
128   @drainer ||= @body.each
129   chunk = @drainer.next
130   chunk.dup
131 rescue StopIteration
132   nil
133 rescue StandardError => e
134   @drain_error = e
135   nil
136 end
expects?()
[show source]
    # File lib/httpx/request.rb
270 def expects?
271   @headers["expect"] == "100-continue" && @informational_status == 100 && !@response
272 end
initialize_with_escape(verb, uri, options = {})
[show source]
   # File lib/httpx/request.rb
71 def initialize_with_escape(verb, uri, options = {})
72   initialize_without_escape(verb, URIParser.escape(uri.to_s), options)
73 end
inspect()

:nocov:

[show source]
    # File lib/httpx/request.rb
139 def inspect
140   "#<HTTPX::Request:#{object_id} " \
141     "#{@verb.to_s.upcase} " \
142     "#{uri} " \
143     "@headers=#{@headers} " \
144     "@body=#{@body}>"
145 end
interests()
[show source]
   # File lib/httpx/request.rb
62 def interests
63   return :r if @state == :done || @state == :expect
64 
65   :w
66 end
merge_headers(h)
[show source]
   # File lib/httpx/request.rb
78 def merge_headers(h)
79   @headers = @headers.merge(h)
80 end
origin()
[show source]
    # File lib/httpx/request.rb
110 def origin
111   @uri.origin
112 end
path()
[show source]
    # File lib/httpx/request.rb
 96 def path
 97   path = uri.path.dup
 98   path =  +"" if path.nil?
 99   path << "/" if path.empty?
100   path << "?#{query}" unless query.empty?
101   path
102 end
query()
[show source]
    # File lib/httpx/request.rb
114 def query
115   return @query if defined?(@query)
116 
117   query = []
118   if (q = @options.params)
119     query << Transcoder.registry("form").encode(q)
120   end
121   query << @uri.query if @uri.query
122   @query = query.join("&")
123 end
read_timeout()
[show source]
   # File lib/httpx/request.rb
42 def read_timeout
43   @options.timeout[:read_timeout]
44 end
request_timeout()
[show source]
   # File lib/httpx/request.rb
50 def request_timeout
51   @options.timeout[:request_timeout]
52 end
response=(response)
[show source]
   # File lib/httpx/request.rb
86 def response=(response)
87   return unless response
88 
89   if response.is_a?(Response) && response.status == 100 && @headers.key?("expect")
90     @informational_status = response.status
91     return
92   end
93   @response = response
94 end
scheme()
[show source]
   # File lib/httpx/request.rb
82 def scheme
83   @uri.scheme
84 end
trailers()
[show source]
   # File lib/httpx/request.rb
58 def trailers
59   @trailers ||= @options.headers_class.new
60 end
trailers?()
[show source]
   # File lib/httpx/request.rb
54 def trailers?
55   defined?(@trailers)
56 end
transition(nextstate)
[show source]
    # File lib/httpx/request.rb
236 def transition(nextstate)
237   case nextstate
238   when :idle
239     @body.rewind
240     @response = nil
241     @drainer = nil
242   when :headers
243     return unless @state == :idle
244   when :body
245     return unless @state == :headers ||
246                   @state == :expect
247 
248     if @headers.key?("expect")
249       if @informational_status && @informational_status == 100
250         # check for 100 Continue response, and deallocate the var
251         # if @informational_status == 100
252         #   @response = nil
253         # end
254       else
255         return if @state == :expect # do not re-set it
256 
257         nextstate = :expect
258       end
259     end
260   when :trailers
261     return unless @state == :body
262   when :done
263     return if @state == :expect
264   end
265   @state = nextstate
266   emit(@state, self)
267   nil
268 end
write_timeout()
[show source]
   # File lib/httpx/request.rb
46 def write_timeout
47   @options.timeout[:write_timeout]
48 end