Class: UV::Http::Request
- Inherits:
-
Libuv::Q::DeferredPromise
- Object
- Libuv::Q::DeferredPromise
- UV::Http::Request
show all
- Includes:
- Encoding
- Defined in:
- lib/uv-rays/http/request.rb
Constant Summary
collapse
- COOKIE =
'cookie'
- CONNECTION =
:Connection
- CRLF =
"\r\n"
Constants included
from Encoding
Encoding::FIELD_ENCODING, Encoding::HTTP_REQUEST_HEADER
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Encoding
#bytesize, #encode_auth, #encode_cookie, #encode_field, #encode_headers, #encode_param, #encode_query, #encode_request, #escape, #form_encode_body, #munge_header_keys, #unescape
Constructor Details
#initialize(endpoint, options, using_ntlm) ⇒ Request
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/uv-rays/http/request.rb', line 26
def initialize(endpoint, options, using_ntlm)
super(endpoint.loop, endpoint.loop.defer)
@options = options
@endpoint = endpoint
@ntlm_retries = using_ntlm ? 0 : nil
@path = options[:path]
@method = options[:method]
@uri = "#{endpoint.scheme}#{encode_host(endpoint.host, endpoint.port)}#{@path}"
end
|
Instance Attribute Details
Returns the value of attribute headers.
14
15
16
|
# File 'lib/uv-rays/http/request.rb', line 14
def
end
|
#method ⇒ Object
Returns the value of attribute method.
13
14
15
|
# File 'lib/uv-rays/http/request.rb', line 13
def method
@method
end
|
#options ⇒ Object
Returns the value of attribute options.
14
15
16
|
# File 'lib/uv-rays/http/request.rb', line 14
def options
@options
end
|
#path ⇒ Object
Returns the value of attribute path.
12
13
14
|
# File 'lib/uv-rays/http/request.rb', line 12
def path
@path
end
|
Instance Method Details
#cookies_hash ⇒ Object
17
18
19
|
# File 'lib/uv-rays/http/request.rb', line 17
def cookies_hash
@endpoint.cookiejar.get_hash(@uri)
end
|
#execute(transport, error) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/uv-rays/http/request.rb', line 58
def execute(transport, error)
head, body = build_request, @options[:body]
@exec_params = [transport, error]
@endpoint.middleware.each do |m|
head, body = m.request(self, head, body) if m.respond_to?(:request)
end
body = body.is_a?(Hash) ? form_encode_body(body) : body
file = @options[:file]
query = @options[:query]
head['content-length'] = File.size(file) if file
if body
head['content-length'] = body.bytesize
elsif method == :post or method == :put
head['content-length'] ||= 0
end
if !head['content-type'] and @options[:body].is_a? Hash
head['content-type'] = 'application/x-www-form-urlencoded'
end
= encode_request(method, path, query)
<< (head)
<< CRLF
if body
<< body
transport.write().catch error
elsif file
transport.write().catch error
fileRef = @endpoint.loop.file file, File::RDONLY
fileRef.progress do
pSend = fileRef.send_file(transport, :raw)
pSend.catch error
pSend.finally do
fileRef.close
end
end
fileRef.catch error
else
transport.write().catch error
end
end
|
#notify(*args) ⇒ Object
113
114
115
|
# File 'lib/uv-rays/http/request.rb', line 113
def notify(*args)
@defer.notify(*args)
end
|
124
125
126
127
128
129
130
131
|
# File 'lib/uv-rays/http/request.rb', line 124
def (callback, &blk)
callback ||= blk
if .nil?
= callback
else
callback.call()
end
end
|
#reject(reason) ⇒ Object
54
55
56
|
# File 'lib/uv-rays/http/request.rb', line 54
def reject(reason)
@defer.reject(reason)
end
|
#resolve(response, body) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/uv-rays/http/request.rb', line 38
def resolve(response, body)
if @ntlm_retries && .status == 401 && [:"WWW-Authenticate"] && @ntlm_retries < 3
@options[:headers][:Authorization] = @endpoint.([:"WWW-Authenticate"])
@ntlm_retries += 1
response.request = self
execute(*@exec_params)
else
@exec_params = nil
@defer.resolve({
headers: ,
body: body
})
end
end
|
#set_cookie(value) ⇒ Object
21
22
23
|
# File 'lib/uv-rays/http/request.rb', line 21
def set_cookie(value)
@endpoint.cookiejar.set(@uri, value)
end
|
117
118
119
120
121
122
|
# File 'lib/uv-rays/http/request.rb', line 117
def (head)
= head
if not .nil?
.call()
end
end
|