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
- USER_AGENT =
"httpx.rb/#{VERSION}"
- URIParser =
URI::DEFAULT_PARSER
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Callbacks
#callbacks_for?, #emit, #on, #once, #only
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
14
15
16
|
# File 'lib/httpx/request.rb', line 14
def body
@body
end
|
#drain_error ⇒ Object
Exception raised during enumerable body writes
17
18
19
|
# File 'lib/httpx/request.rb', line 17
def drain_error
@drain_error
end
|
Returns the value of attribute headers.
14
15
16
|
# File 'lib/httpx/request.rb', line 14
def
@headers
end
|
#options ⇒ Object
Returns the value of attribute options.
14
15
16
|
# File 'lib/httpx/request.rb', line 14
def options
@options
end
|
#response ⇒ Object
Returns the value of attribute response.
14
15
16
|
# File 'lib/httpx/request.rb', line 14
def response
@response
end
|
#state ⇒ Object
Returns the value of attribute state.
14
15
16
|
# File 'lib/httpx/request.rb', line 14
def state
@state
end
|
#uri ⇒ Object
Returns the value of attribute uri.
14
15
16
|
# File 'lib/httpx/request.rb', line 14
def uri
@uri
end
|
#verb ⇒ Object
Returns the value of attribute verb.
14
15
16
|
# File 'lib/httpx/request.rb', line 14
def verb
@verb
end
|
Instance Method Details
#authority ⇒ Object
111
112
113
|
# File 'lib/httpx/request.rb', line 111
def authority
@uri.authority
end
|
#drain_body ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/httpx/request.rb', line 131
def drain_body
return nil if @body.nil?
@drainer ||= @body.each
chunk = @drainer.next.dup
emit(:body_chunk, chunk)
chunk
rescue StopIteration
nil
rescue StandardError => e
@drain_error = e
nil
end
|
#expects? ⇒ Boolean
284
285
286
|
# File 'lib/httpx/request.rb', line 284
def expects?
@headers["expect"] == "100-continue" && @informational_status == 100 && !@response
end
|
#initialize_with_escape(verb, uri, options = {}) ⇒ Object
Also known as:
initialize
75
76
77
|
# File 'lib/httpx/request.rb', line 75
def initialize_with_escape(verb, uri, options = {})
initialize_without_escape(verb, URIParser.escape(uri.to_s), options)
end
|
#inspect ⇒ Object
147
148
149
150
151
152
153
|
# File 'lib/httpx/request.rb', line 147
def inspect
"#<HTTPX::Request:#{object_id} " \
"#{@verb} " \
"#{uri} " \
"@headers=#{@headers} " \
"@body=#{@body}>"
end
|
#interests ⇒ Object
66
67
68
69
70
|
# File 'lib/httpx/request.rb', line 66
def interests
return :r if @state == :done || @state == :expect
:w
end
|
82
83
84
|
# File 'lib/httpx/request.rb', line 82
def (h)
@headers = @headers.merge(h)
end
|
#origin ⇒ Object
116
117
118
|
# File 'lib/httpx/request.rb', line 116
def origin
@uri.origin
end
|
#path ⇒ Object
102
103
104
105
106
107
108
|
# File 'lib/httpx/request.rb', line 102
def path
path = uri.path.dup
path = +"" if path.nil?
path << "/" if path.empty?
path << "?#{query}" unless query.empty?
path
end
|
#query ⇒ Object
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/httpx/request.rb', line 120
def query
return @query if defined?(@query)
query = []
if (q = @options.params)
query << Transcoder::Form.encode(q)
end
query << @uri.query if @uri.query
@query = query.join("&")
end
|
#read_timeout ⇒ Object
46
47
48
|
# File 'lib/httpx/request.rb', line 46
def read_timeout
@options.timeout[:read_timeout]
end
|
#request_timeout ⇒ Object
54
55
56
|
# File 'lib/httpx/request.rb', line 54
def request_timeout
@options.timeout[:request_timeout]
end
|
#scheme ⇒ Object
86
87
88
|
# File 'lib/httpx/request.rb', line 86
def scheme
@uri.scheme
end
|
#trailers ⇒ Object
62
63
64
|
# File 'lib/httpx/request.rb', line 62
def trailers
@trailers ||= @options..new
end
|
#trailers? ⇒ Boolean
58
59
60
|
# File 'lib/httpx/request.rb', line 58
def trailers?
defined?(@trailers)
end
|
#transition(nextstate) ⇒ Object
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
277
278
279
280
281
282
|
# File 'lib/httpx/request.rb', line 250
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
|
#write_timeout ⇒ Object
50
51
52
|
# File 'lib/httpx/request.rb', line 50
def write_timeout
@options.timeout[:write_timeout]
end
|