Class: HTTPX::Request
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Includes:
- Callbacks
- Defined in:
- lib/httpx/request.rb
Defined Under Namespace
Classes: Body, ProcIO
Constant Summary
collapse
- METHODS =
[
:options, :get, :head, :post, :put, :delete, :trace, :connect,
:propfind, :proppatch, :mkcol, :copy, :move, :lock, :unlock,
:orderpatch,
:acl,
:report,
:patch,
:search
].freeze
- USER_AGENT =
"httpx.rb/#{VERSION}"
- URIParser =
URI::DEFAULT_PARSER
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Callbacks
#emit, #on, #once, #only
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
37
38
39
|
# File 'lib/httpx/request.rb', line 37
def body
@body
end
|
#drain_error ⇒ Object
Exception raised during enumerable body writes
40
41
42
|
# File 'lib/httpx/request.rb', line 40
def drain_error
@drain_error
end
|
Returns the value of attribute headers.
37
38
39
|
# File 'lib/httpx/request.rb', line 37
def
@headers
end
|
#options ⇒ Object
Returns the value of attribute options.
37
38
39
|
# File 'lib/httpx/request.rb', line 37
def options
@options
end
|
#response ⇒ Object
Returns the value of attribute response.
37
38
39
|
# File 'lib/httpx/request.rb', line 37
def response
@response
end
|
#state ⇒ Object
Returns the value of attribute state.
37
38
39
|
# File 'lib/httpx/request.rb', line 37
def state
@state
end
|
#uri ⇒ Object
Returns the value of attribute uri.
37
38
39
|
# File 'lib/httpx/request.rb', line 37
def uri
@uri
end
|
#verb ⇒ Object
Returns the value of attribute verb.
37
38
39
|
# File 'lib/httpx/request.rb', line 37
def verb
@verb
end
|
Instance Method Details
#authority ⇒ Object
115
116
117
|
# File 'lib/httpx/request.rb', line 115
def authority
@uri.authority
end
|
#drain_body ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/httpx/request.rb', line 135
def drain_body
return nil if @body.nil?
@drainer ||= @body.each
chunk = @drainer.next
chunk.dup
rescue StopIteration
nil
rescue StandardError => e
@drain_error = e
nil
end
|
#expects? ⇒ Boolean
278
279
280
|
# File 'lib/httpx/request.rb', line 278
def expects?
@headers["expect"] == "100-continue" && @informational_status == 100 && !@response
end
|
#initialize_with_escape(verb, uri, options = {}) ⇒ Object
Also known as:
initialize
82
83
84
|
# File 'lib/httpx/request.rb', line 82
def initialize_with_escape(verb, uri, options = {})
initialize_without_escape(verb, URIParser.escape(uri.to_s), options)
end
|
#inspect ⇒ Object
149
150
151
152
153
154
155
|
# File 'lib/httpx/request.rb', line 149
def inspect
"#<HTTPX::Request:#{object_id} " \
"#{@verb.to_s.upcase} " \
"#{uri} " \
"@headers=#{@headers} " \
"@body=#{@body}>"
end
|
#interests ⇒ Object
73
74
75
76
77
|
# File 'lib/httpx/request.rb', line 73
def interests
return :r if @state == :done || @state == :expect
:w
end
|
89
90
91
|
# File 'lib/httpx/request.rb', line 89
def (h)
@headers = @headers.merge(h)
end
|
#origin ⇒ Object
120
121
122
|
# File 'lib/httpx/request.rb', line 120
def origin
@uri.origin
end
|
#path ⇒ Object
107
108
109
110
111
112
|
# File 'lib/httpx/request.rb', line 107
def path
path = uri.path.dup
path << "/" if path.empty?
path << "?#{query}" unless query.empty?
path
end
|
#query ⇒ Object
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/httpx/request.rb', line 124
def query
return @query if defined?(@query)
query = []
if (q = @options.params)
query << Transcoder.registry("form").encode(q)
end
query << @uri.query if @uri.query
@query = query.join("&")
end
|
#scheme ⇒ Object
93
94
95
|
# File 'lib/httpx/request.rb', line 93
def scheme
@uri.scheme
end
|
#trailers ⇒ Object
69
70
71
|
# File 'lib/httpx/request.rb', line 69
def trailers
@trailers ||= @options..new
end
|
#trailers? ⇒ Boolean
65
66
67
|
# File 'lib/httpx/request.rb', line 65
def trailers?
defined?(@trailers)
end
|
#transition(nextstate) ⇒ Object
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
# File 'lib/httpx/request.rb', line 244
def transition(nextstate)
case nextstate
when :idle
@body.rewind
@response = nil
@drainer = nil
when :headers
return unless @state == :idle
when :body
return unless @state == :headers ||
@state == :expect
if @headers.key?("expect")
if @informational_status && @informational_status == 100
else
return if @state == :expect
nextstate = :expect
end
end
when :trailers
return unless @state == :body
when :done
return if @state == :expect
end
@state = nextstate
emit(@state, self)
nil
end
|