ronin-support 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -0
- data/ChangeLog.md +42 -1
- data/README.md +4 -1
- data/gemspec.yml +2 -1
- data/lib/ronin/extensions.rb +2 -0
- data/lib/ronin/extensions/enumerable.rb +54 -0
- data/lib/ronin/extensions/file.rb +70 -2
- data/lib/ronin/extensions/ip_addr.rb +45 -45
- data/lib/ronin/extensions/regexp.rb +45 -0
- data/lib/ronin/extensions/resolv.rb +80 -0
- data/lib/ronin/extensions/string.rb +35 -32
- data/lib/ronin/formatting/extensions/binary/integer.rb +12 -5
- data/lib/ronin/formatting/extensions/binary/string.rb +44 -16
- data/lib/ronin/formatting/extensions/html/integer.rb +51 -31
- data/lib/ronin/formatting/extensions/html/string.rb +50 -31
- data/lib/ronin/formatting/extensions/http/integer.rb +10 -2
- data/lib/ronin/formatting/extensions/sql.rb +20 -0
- data/lib/ronin/formatting/extensions/sql/string.rb +98 -0
- data/lib/ronin/formatting/extensions/text/array.rb +11 -9
- data/lib/ronin/formatting/extensions/text/string.rb +213 -29
- data/lib/ronin/formatting/sql.rb +20 -0
- data/lib/ronin/network/extensions/http.rb +1 -0
- data/lib/ronin/network/extensions/http/net.rb +2 -2
- data/lib/ronin/network/extensions/http/uri/http.rb +226 -0
- data/lib/ronin/network/extensions/imap/net.rb +1 -1
- data/lib/ronin/network/extensions/ssl/net.rb +7 -1
- data/lib/ronin/network/http/proxy.rb +20 -21
- data/lib/ronin/network/mixins.rb +27 -0
- data/lib/ronin/network/mixins/esmtp.rb +165 -0
- data/lib/ronin/network/mixins/http.rb +723 -0
- data/lib/ronin/network/mixins/imap.rb +151 -0
- data/lib/ronin/network/mixins/pop3.rb +141 -0
- data/lib/ronin/network/mixins/smtp.rb +159 -0
- data/lib/ronin/network/mixins/tcp.rb +331 -0
- data/lib/ronin/network/mixins/telnet.rb +199 -0
- data/lib/ronin/network/mixins/udp.rb +227 -0
- data/lib/ronin/network/ssl.rb +17 -11
- data/lib/ronin/path.rb +3 -3
- data/lib/ronin/spec/ui/output.rb +28 -0
- data/lib/ronin/support.rb +3 -0
- data/lib/ronin/support/version.rb +1 -1
- data/lib/ronin/ui/output.rb +21 -0
- data/lib/ronin/ui/output/helpers.rb +248 -0
- data/lib/ronin/ui/output/output.rb +146 -0
- data/lib/ronin/ui/output/terminal.rb +21 -0
- data/lib/ronin/ui/output/terminal/color.rb +118 -0
- data/lib/ronin/ui/output/terminal/raw.rb +103 -0
- data/lib/ronin/ui/shell.rb +219 -0
- data/ronin-support.gemspec +1 -1
- data/spec/extensions/enumerable_spec.rb +24 -0
- data/spec/extensions/file_spec.rb +39 -0
- data/spec/extensions/ip_addr_spec.rb +6 -0
- data/spec/extensions/resolv_spec.rb +18 -0
- data/spec/formatting/html/integer_spec.rb +2 -2
- data/spec/formatting/html/string_spec.rb +1 -1
- data/spec/formatting/sql/string_spec.rb +55 -0
- data/spec/formatting/text/string_spec.rb +110 -0
- data/spec/network/ssl_spec.rb +10 -4
- data/spec/ui/classes/test_shell.rb +22 -0
- data/spec/ui/output_spec.rb +32 -0
- data/spec/ui/shell_spec.rb +79 -0
- metadata +132 -90
@@ -0,0 +1,723 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
3
|
+
#
|
4
|
+
# This file is part of Ronin Support.
|
5
|
+
#
|
6
|
+
# Ronin Support is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Lesser General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Ronin Support is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public License
|
17
|
+
# along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'ronin/network/http'
|
21
|
+
require 'ronin/ui/output/helpers'
|
22
|
+
require 'ronin/mixin'
|
23
|
+
|
24
|
+
require 'parameters'
|
25
|
+
|
26
|
+
module Ronin
|
27
|
+
module Network
|
28
|
+
module Mixins
|
29
|
+
#
|
30
|
+
# Adds HTTP convenience methods and connection parameters to a class.
|
31
|
+
#
|
32
|
+
# Defines the following parameters:
|
33
|
+
#
|
34
|
+
# * `host` (`String`) - HTTP host.
|
35
|
+
# * `port` (`Integer`) - HTTP port. Defaults to `Net::HTTP.default_port`.
|
36
|
+
# * `http_vhost` (`String`) - HTTP Host header to send.
|
37
|
+
# * `http_user` (`String`) - HTTP user to authenticate as.
|
38
|
+
# * `http_password` (`String`) - HTTP password to authenticate with.
|
39
|
+
# * `http_proxy` - HTTP proxy information.
|
40
|
+
# * `http_user_agent` (`String`) - HTTP User-Agent header to send.
|
41
|
+
#
|
42
|
+
module HTTP
|
43
|
+
include Mixin
|
44
|
+
|
45
|
+
mixin UI::Output::Helpers, Parameters
|
46
|
+
|
47
|
+
mixin do
|
48
|
+
# HTTP host
|
49
|
+
parameter :host, :type => String,
|
50
|
+
:description => 'HTTP host'
|
51
|
+
|
52
|
+
# HTTP port
|
53
|
+
parameter :port, :default => Net::HTTP.default_port,
|
54
|
+
:description => 'HTTP port'
|
55
|
+
|
56
|
+
# HTTP `Host` header to send
|
57
|
+
parameter :http_vhost, :type => String,
|
58
|
+
:description => 'HTTP Host header to send'
|
59
|
+
|
60
|
+
# HTTP user to authenticate as
|
61
|
+
parameter :http_user, :type => String,
|
62
|
+
:description => 'HTTP user to authenticate as'
|
63
|
+
|
64
|
+
# HTTP password to authenticate with
|
65
|
+
parameter :http_password, :type => String,
|
66
|
+
:description => 'HTTP password to authenticate with'
|
67
|
+
|
68
|
+
# HTTP proxy information
|
69
|
+
parameter :http_proxy, :description => 'HTTP proxy information'
|
70
|
+
|
71
|
+
# HTTP `User-Agent` header to send
|
72
|
+
parameter :http_user_agent, :type => String,
|
73
|
+
:description => 'HTTP User-Agent header to send'
|
74
|
+
end
|
75
|
+
|
76
|
+
protected
|
77
|
+
|
78
|
+
#
|
79
|
+
# Resets the HTTP proxy settings.
|
80
|
+
#
|
81
|
+
# @api public
|
82
|
+
#
|
83
|
+
def disable_http_proxy
|
84
|
+
@http_proxy = nil
|
85
|
+
end
|
86
|
+
|
87
|
+
#
|
88
|
+
# Connects to the HTTP server.
|
89
|
+
#
|
90
|
+
# @param [Hash] options
|
91
|
+
# Additional options
|
92
|
+
#
|
93
|
+
# @option options [String, URI::HTTP] :url
|
94
|
+
# The full URL to request.
|
95
|
+
#
|
96
|
+
# @option options [String] :user
|
97
|
+
# The user to authenticate with when connecting to the HTTP
|
98
|
+
# server.
|
99
|
+
#
|
100
|
+
# @option options [String] :password
|
101
|
+
# The password to authenticate with when connecting to the HTTP
|
102
|
+
# server.
|
103
|
+
#
|
104
|
+
# @option options [String] :host
|
105
|
+
# The host the HTTP server is running on.
|
106
|
+
#
|
107
|
+
# @option options [Integer] :port (Net::HTTP.default_port)
|
108
|
+
# The port the HTTP server is listening on.
|
109
|
+
#
|
110
|
+
# @option options [String] :path
|
111
|
+
# The path to request from the HTTP server.
|
112
|
+
#
|
113
|
+
# @yield [session]
|
114
|
+
# If a block is given, it will be passes the new HTTP session
|
115
|
+
# object.
|
116
|
+
#
|
117
|
+
# @yieldparam [Net::HTTP] session
|
118
|
+
# The newly created HTTP session.
|
119
|
+
#
|
120
|
+
# @return [Net::HTTP]
|
121
|
+
# The HTTP session object.
|
122
|
+
#
|
123
|
+
# @api public
|
124
|
+
#
|
125
|
+
def http_session(options={})
|
126
|
+
options = http_merge_options(options)
|
127
|
+
host_port = "#{options[:host]}:#{options[:port]}"
|
128
|
+
|
129
|
+
Net.http_session(options) do |http|
|
130
|
+
print_info "Starting HTTP Session with #{host_port}"
|
131
|
+
|
132
|
+
yield http
|
133
|
+
|
134
|
+
print_info "Closing HTTP Session with #{host_port}"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
#
|
139
|
+
# Connects to the HTTP server and sends an HTTP Request.
|
140
|
+
#
|
141
|
+
# @param [Hash] options
|
142
|
+
# Additional options.
|
143
|
+
#
|
144
|
+
# @option options [Hash{String,Symbol => Object}] :headers
|
145
|
+
# The Hash of the HTTP headers to send with the request.
|
146
|
+
# May contain either Strings or Symbols, lower-case or
|
147
|
+
# camel-case keys.
|
148
|
+
#
|
149
|
+
# @yield [request, (options)]
|
150
|
+
# If a block is given, it will be passed the HTTP request object.
|
151
|
+
# If the block has an arity of 2, it will also be passed the
|
152
|
+
# expanded version of the given options.
|
153
|
+
#
|
154
|
+
# @yieldparam [Net::HTTP::Request] request
|
155
|
+
# The HTTP request object to use in the request.
|
156
|
+
#
|
157
|
+
# @yieldparam [Hash] options
|
158
|
+
# The expanded version of the given options.
|
159
|
+
#
|
160
|
+
# @return [Net::HTTP::Response]
|
161
|
+
# The response of the HTTP request.
|
162
|
+
#
|
163
|
+
# @see #http_session
|
164
|
+
#
|
165
|
+
# @api public
|
166
|
+
#
|
167
|
+
def http_request(options={},&block)
|
168
|
+
options = http_merge_options(options)
|
169
|
+
print_info "HTTP #{options[:method]} #{http_options_to_s(options)}"
|
170
|
+
|
171
|
+
return Net.http_request(options,&block)
|
172
|
+
end
|
173
|
+
|
174
|
+
#
|
175
|
+
# Returns the Status Code of the Response.
|
176
|
+
#
|
177
|
+
# @param [Hash] options
|
178
|
+
# Additional options.
|
179
|
+
#
|
180
|
+
# @option options [Symbol, String] :method (:head)
|
181
|
+
# The method to use for the request.
|
182
|
+
#
|
183
|
+
# @return [Integer]
|
184
|
+
# The HTTP Response Status.
|
185
|
+
#
|
186
|
+
# @see #http_request
|
187
|
+
#
|
188
|
+
# @since 1.1.0
|
189
|
+
#
|
190
|
+
# @api public
|
191
|
+
#
|
192
|
+
def http_status(options={})
|
193
|
+
options = http_merge_options(options)
|
194
|
+
|
195
|
+
if (result = Net.http_status(options))
|
196
|
+
print_debug "HTTP #{result} #{http_options_to_s(options)}"
|
197
|
+
end
|
198
|
+
|
199
|
+
return result
|
200
|
+
end
|
201
|
+
|
202
|
+
#
|
203
|
+
# Checks if the response has an HTTP OK status code.
|
204
|
+
#
|
205
|
+
# @param [Hash] options
|
206
|
+
# Additional options.
|
207
|
+
#
|
208
|
+
# @option options [Symbol, String] :method (:head)
|
209
|
+
# The method to use for the request.
|
210
|
+
#
|
211
|
+
# @return [Boolean]
|
212
|
+
# Specifies whether the response had an HTTP OK status code or not.
|
213
|
+
#
|
214
|
+
# @see #http_status
|
215
|
+
#
|
216
|
+
# @since 1.1.0
|
217
|
+
#
|
218
|
+
# @api public
|
219
|
+
#
|
220
|
+
def http_ok?(options={})
|
221
|
+
options = http_merge_options(options)
|
222
|
+
|
223
|
+
if (result = Net.http_ok?(options))
|
224
|
+
print_debug "HTTP 200 OK #{http_options_to_s(options)}"
|
225
|
+
end
|
226
|
+
|
227
|
+
return result
|
228
|
+
end
|
229
|
+
|
230
|
+
#
|
231
|
+
# Sends a HTTP Head request and returns the HTTP Server header.
|
232
|
+
#
|
233
|
+
# @param [Hash] options
|
234
|
+
# Additional options.
|
235
|
+
#
|
236
|
+
# @option options [Symbol, String] :method (:head)
|
237
|
+
# The method to use for the request.
|
238
|
+
#
|
239
|
+
# @return [String]
|
240
|
+
# The HTTP `Server` header.
|
241
|
+
#
|
242
|
+
# @see #http_request
|
243
|
+
#
|
244
|
+
# @since 1.1.0
|
245
|
+
#
|
246
|
+
# @api public
|
247
|
+
#
|
248
|
+
def http_server(options={})
|
249
|
+
options = http_merge_options(options)
|
250
|
+
|
251
|
+
if (result = Net.http_server(options))
|
252
|
+
print_debug "HTTP Server: #{result}"
|
253
|
+
end
|
254
|
+
|
255
|
+
return result
|
256
|
+
end
|
257
|
+
|
258
|
+
#
|
259
|
+
# Sends an HTTP Head request and returns the HTTP X-Powered-By header.
|
260
|
+
#
|
261
|
+
# @param [Hash] options
|
262
|
+
# Additional options.
|
263
|
+
#
|
264
|
+
# @option options [Symbol, String] :method (:get)
|
265
|
+
# The method to use for the request.
|
266
|
+
#
|
267
|
+
# @return [String]
|
268
|
+
# The HTTP `X-Powered-By` header.
|
269
|
+
#
|
270
|
+
# @see #http_request
|
271
|
+
#
|
272
|
+
# @since 1.1.0
|
273
|
+
#
|
274
|
+
# @api public
|
275
|
+
#
|
276
|
+
def http_powered_by(options={})
|
277
|
+
options = http_merge_options(options)
|
278
|
+
|
279
|
+
if (result = Net.http_powered_by(options))
|
280
|
+
print_debug "HTTP X-Powered-By: #{result}"
|
281
|
+
end
|
282
|
+
|
283
|
+
return result
|
284
|
+
end
|
285
|
+
|
286
|
+
#
|
287
|
+
# Performs an HTTP Copy request.
|
288
|
+
#
|
289
|
+
# @yield [response]
|
290
|
+
# If a block is given, it will be passed the response received
|
291
|
+
# from the request.
|
292
|
+
#
|
293
|
+
# @yieldparam [Net::HTTP::Response] response
|
294
|
+
# The HTTP response object.
|
295
|
+
#
|
296
|
+
# @return [Net::HTTP::Response]
|
297
|
+
# The response of the HTTP request.
|
298
|
+
#
|
299
|
+
# @see #http_request
|
300
|
+
#
|
301
|
+
# @api public
|
302
|
+
#
|
303
|
+
def http_copy(options={},&block)
|
304
|
+
options = http_merge_options(options)
|
305
|
+
print_info "HTTP COPY #{http_options_to_s(options)}"
|
306
|
+
|
307
|
+
return Net.http_copy(options,&block)
|
308
|
+
end
|
309
|
+
|
310
|
+
#
|
311
|
+
# Performs an HTTP Delete request.
|
312
|
+
#
|
313
|
+
# @yield [response]
|
314
|
+
# If a block is given, it will be passed the response received
|
315
|
+
# from the request.
|
316
|
+
#
|
317
|
+
# @yieldparam [Net::HTTP::Response] response
|
318
|
+
# The HTTP response object.
|
319
|
+
#
|
320
|
+
# @return [Net::HTTP::Response]
|
321
|
+
# The response of the HTTP request.
|
322
|
+
#
|
323
|
+
# @see #http_request
|
324
|
+
#
|
325
|
+
# @api public
|
326
|
+
#
|
327
|
+
def http_delete(options={},&block)
|
328
|
+
options = http_merge_options(options)
|
329
|
+
print_info "HTTP DELETE #{http_options_to_s(options)}"
|
330
|
+
|
331
|
+
return Net.http_delete(options,&block)
|
332
|
+
end
|
333
|
+
|
334
|
+
#
|
335
|
+
# Performs an HTTP Get request.
|
336
|
+
#
|
337
|
+
# @yield [response]
|
338
|
+
# If a block is given, it will be passed the response received
|
339
|
+
# from the request.
|
340
|
+
#
|
341
|
+
# @yieldparam [Net::HTTP::Response] response
|
342
|
+
# The HTTP response object.
|
343
|
+
#
|
344
|
+
# @return [Net::HTTP::Response]
|
345
|
+
# The response of the HTTP request.
|
346
|
+
#
|
347
|
+
# @see #http_request
|
348
|
+
#
|
349
|
+
# @api public
|
350
|
+
#
|
351
|
+
def http_get(options={},&block)
|
352
|
+
options = http_merge_options(options)
|
353
|
+
print_info "HTTP GET #{http_options_to_s(options)}"
|
354
|
+
|
355
|
+
return Net.http_get(options,&block)
|
356
|
+
end
|
357
|
+
|
358
|
+
#
|
359
|
+
# Performs an HTTP Get request.
|
360
|
+
#
|
361
|
+
# @yield [response]
|
362
|
+
# If a block is given, it will be passed the response received
|
363
|
+
# from the request.
|
364
|
+
#
|
365
|
+
# @yieldparam [Net::HTTP::Response] response
|
366
|
+
# The HTTP response object.
|
367
|
+
#
|
368
|
+
# @return [String]
|
369
|
+
# The body of the HTTP Get request.
|
370
|
+
#
|
371
|
+
# @see #http_get
|
372
|
+
#
|
373
|
+
# @api public
|
374
|
+
#
|
375
|
+
def http_get_body(options={},&block)
|
376
|
+
options = http_merge_options(options)
|
377
|
+
print_info "HTTP GET #{http_options_to_s(options)}"
|
378
|
+
|
379
|
+
return Net.http_get_body(options,&block)
|
380
|
+
end
|
381
|
+
|
382
|
+
#
|
383
|
+
# Performs an HTTP Head request.
|
384
|
+
#
|
385
|
+
# @yield [response]
|
386
|
+
# If a block is given, it will be passed the response received
|
387
|
+
# from the request.
|
388
|
+
#
|
389
|
+
# @yieldparam [Net::HTTP::Response] response
|
390
|
+
# The HTTP response object.
|
391
|
+
#
|
392
|
+
# @return [Net::HTTP::Response]
|
393
|
+
# The response of the HTTP request.
|
394
|
+
#
|
395
|
+
# @see #http_request
|
396
|
+
#
|
397
|
+
# @api public
|
398
|
+
#
|
399
|
+
def http_head(options={},&block)
|
400
|
+
options = http_merge_options(options)
|
401
|
+
print_info "HTTP HEAD #{http_options_to_s(options)}"
|
402
|
+
|
403
|
+
return Net.http_head(options,&block)
|
404
|
+
end
|
405
|
+
|
406
|
+
#
|
407
|
+
# Performs an HTTP Lock request.
|
408
|
+
#
|
409
|
+
# @yield [response]
|
410
|
+
# If a block is given, it will be passed the response received
|
411
|
+
# from the request.
|
412
|
+
#
|
413
|
+
# @yieldparam [Net::HTTP::Response] response
|
414
|
+
# The HTTP response object.
|
415
|
+
#
|
416
|
+
# @return [Net::HTTP::Response]
|
417
|
+
# The response of the HTTP request.
|
418
|
+
#
|
419
|
+
# @see #http_request
|
420
|
+
#
|
421
|
+
# @api public
|
422
|
+
#
|
423
|
+
def http_lock(options={},&block)
|
424
|
+
options = http_merge_options(options)
|
425
|
+
print_info "HTTP LOCK #{http_options_to_s(options)}"
|
426
|
+
|
427
|
+
return Net.http_lock(options,&block)
|
428
|
+
end
|
429
|
+
|
430
|
+
#
|
431
|
+
# Performs an HTTP Mkcol request.
|
432
|
+
#
|
433
|
+
# @yield [response]
|
434
|
+
# If a block is given, it will be passed the response received
|
435
|
+
# from the request.
|
436
|
+
#
|
437
|
+
# @yieldparam [Net::HTTP::Response] response
|
438
|
+
# The HTTP response object.
|
439
|
+
#
|
440
|
+
# @return [Net::HTTP::Response]
|
441
|
+
# The response of the HTTP request.
|
442
|
+
#
|
443
|
+
# @see #http_request
|
444
|
+
#
|
445
|
+
# @api public
|
446
|
+
#
|
447
|
+
def http_mkcol(options={},&block)
|
448
|
+
options = http_merge_options(options)
|
449
|
+
print_info "HTTP MKCOL #{http_options_to_s(options)}"
|
450
|
+
|
451
|
+
return Net.http_mkcol(options,&block)
|
452
|
+
end
|
453
|
+
|
454
|
+
#
|
455
|
+
# Performs an HTTP Move request.
|
456
|
+
#
|
457
|
+
# @yield [response]
|
458
|
+
# If a block is given, it will be passed the response received
|
459
|
+
# from the request.
|
460
|
+
#
|
461
|
+
# @yieldparam [Net::HTTP::Response] response
|
462
|
+
# The HTTP response object.
|
463
|
+
#
|
464
|
+
# @return [Net::HTTP::Response]
|
465
|
+
# The response of the HTTP request.
|
466
|
+
#
|
467
|
+
# @see #http_request
|
468
|
+
#
|
469
|
+
# @api public
|
470
|
+
#
|
471
|
+
def http_move(options={},&block)
|
472
|
+
options = http_merge_options(options)
|
473
|
+
print_info "HTTP MOVE #{http_options_to_s(options)}"
|
474
|
+
|
475
|
+
return Net.http_move(options,&block)
|
476
|
+
end
|
477
|
+
|
478
|
+
#
|
479
|
+
# Performs an HTTP Options request.
|
480
|
+
#
|
481
|
+
# @yield [response]
|
482
|
+
# If a block is given, it will be passed the response received
|
483
|
+
# from the request.
|
484
|
+
#
|
485
|
+
# @yieldparam [Net::HTTP::Response] response
|
486
|
+
# The HTTP response object.
|
487
|
+
#
|
488
|
+
# @return [Net::HTTP::Response]
|
489
|
+
# The response of the HTTP request.
|
490
|
+
#
|
491
|
+
# @see #http_request
|
492
|
+
#
|
493
|
+
# @api public
|
494
|
+
#
|
495
|
+
def http_options(options={},&block)
|
496
|
+
options = http_merge_options(options)
|
497
|
+
print_info "HTTP OPTIONS #{http_options_to_s(options)}"
|
498
|
+
|
499
|
+
return Net.http_options(options,&block)
|
500
|
+
end
|
501
|
+
|
502
|
+
#
|
503
|
+
# Performs an HTTP Post request.
|
504
|
+
#
|
505
|
+
# @param [Hash] options
|
506
|
+
# Additional options.
|
507
|
+
#
|
508
|
+
# @option options [String] :post_data
|
509
|
+
# The `POSTDATA` to send with the HTTP Post request.
|
510
|
+
#
|
511
|
+
# @yield [response]
|
512
|
+
# If a block is given, it will be passed the response received
|
513
|
+
# from the request.
|
514
|
+
#
|
515
|
+
# @yieldparam [Net::HTTP::Response] response
|
516
|
+
# The HTTP response object.
|
517
|
+
#
|
518
|
+
# @return [Net::HTTP::Response]
|
519
|
+
# The response of the HTTP request.
|
520
|
+
#
|
521
|
+
# @see #http_request
|
522
|
+
#
|
523
|
+
# @api public
|
524
|
+
#
|
525
|
+
def http_post(options={},&block)
|
526
|
+
options = http_merge_options(options)
|
527
|
+
print_info "HTTP POST #{http_options_to_s(options)}"
|
528
|
+
|
529
|
+
return Net.http_post(options,&block)
|
530
|
+
end
|
531
|
+
|
532
|
+
#
|
533
|
+
# Performs an HTTP Post request.
|
534
|
+
#
|
535
|
+
# @yield [response]
|
536
|
+
# If a block is given, it will be passed the response received
|
537
|
+
# from the request.
|
538
|
+
#
|
539
|
+
# @yieldparam [Net::HTTP::Response] response
|
540
|
+
# The HTTP response object.
|
541
|
+
#
|
542
|
+
# @return [String]
|
543
|
+
# The body of the Post request.
|
544
|
+
#
|
545
|
+
# @see #http_post
|
546
|
+
#
|
547
|
+
# @api public
|
548
|
+
#
|
549
|
+
def http_post_body(options={},&block)
|
550
|
+
options = http_merge_options(options)
|
551
|
+
print_info "HTTP POST #{http_options_to_s(options)}"
|
552
|
+
|
553
|
+
return Net.http_post_body(options,&block)
|
554
|
+
end
|
555
|
+
|
556
|
+
#
|
557
|
+
# Performs an HTTP Propfind request.
|
558
|
+
#
|
559
|
+
# @yield [response]
|
560
|
+
# If a block is given, it will be passed the response received
|
561
|
+
# from the request.
|
562
|
+
#
|
563
|
+
# @yieldparam [Net::HTTP::Response] response
|
564
|
+
# The HTTP response object.
|
565
|
+
#
|
566
|
+
# @return [Net::HTTP::Response]
|
567
|
+
# The response of the HTTP request.
|
568
|
+
#
|
569
|
+
# @see #http_request
|
570
|
+
#
|
571
|
+
# @api public
|
572
|
+
#
|
573
|
+
def http_prop_find(options={},&block)
|
574
|
+
options = http_merge_options(options)
|
575
|
+
print_info "HTTP PROPFIND #{http_options_to_s(options)}"
|
576
|
+
|
577
|
+
return Net.http_prop_find(options,&block)
|
578
|
+
end
|
579
|
+
|
580
|
+
#
|
581
|
+
# Performs an HTTP Proppatch request.
|
582
|
+
#
|
583
|
+
# @yield [response]
|
584
|
+
# If a block is given, it will be passed the response received
|
585
|
+
# from the request.
|
586
|
+
#
|
587
|
+
# @yieldparam [Net::HTTP::Response] response
|
588
|
+
# The HTTP response object.
|
589
|
+
#
|
590
|
+
# @return [Net::HTTP::Response]
|
591
|
+
# The response of the HTTP request.
|
592
|
+
#
|
593
|
+
# @see #http_request
|
594
|
+
#
|
595
|
+
# @api public
|
596
|
+
#
|
597
|
+
def http_prop_patch(options={},&block)
|
598
|
+
options = http_merge_options(options)
|
599
|
+
print_info "HTTP PROPPATCH #{http_options_to_s(options)}"
|
600
|
+
|
601
|
+
return Net.http_prop_patch(options,&block)
|
602
|
+
end
|
603
|
+
|
604
|
+
#
|
605
|
+
# Performs an HTTP Trace request.
|
606
|
+
#
|
607
|
+
# @yield [response]
|
608
|
+
# If a block is given, it will be passed the response received
|
609
|
+
# from the request.
|
610
|
+
#
|
611
|
+
# @yieldparam [Net::HTTP::Response] response
|
612
|
+
# The HTTP response object.
|
613
|
+
#
|
614
|
+
# @return [Net::HTTP::Response]
|
615
|
+
# The response of the HTTP request.
|
616
|
+
#
|
617
|
+
# @see #http_request
|
618
|
+
#
|
619
|
+
# @api public
|
620
|
+
#
|
621
|
+
def http_trace(options={},&block)
|
622
|
+
options = http_merge_options(options)
|
623
|
+
print_info "HTTP TRACE #{http_options_to_s(options)}"
|
624
|
+
|
625
|
+
return Net.http_trace(options,&block)
|
626
|
+
end
|
627
|
+
|
628
|
+
#
|
629
|
+
# Performs an HTTP Unlock request.
|
630
|
+
#
|
631
|
+
# @yield [response]
|
632
|
+
# If a block is given, it will be passed the response received
|
633
|
+
# from the request.
|
634
|
+
#
|
635
|
+
# @yieldparam [Net::HTTP::Response] response
|
636
|
+
# The HTTP response object.
|
637
|
+
#
|
638
|
+
# @return [Net::HTTP::Response]
|
639
|
+
# The response of the HTTP request.
|
640
|
+
#
|
641
|
+
# @see #http_request
|
642
|
+
#
|
643
|
+
# @api public
|
644
|
+
#
|
645
|
+
def http_unlock(options={},&block)
|
646
|
+
options = http_merge_options(options)
|
647
|
+
print_info "HTTP UNLOCK #{http_options_to_s(options)}"
|
648
|
+
|
649
|
+
return Net.http_unlock(options,&block)
|
650
|
+
end
|
651
|
+
|
652
|
+
private
|
653
|
+
|
654
|
+
#
|
655
|
+
# Merges the HTTP parameters into the HTTP options.
|
656
|
+
#
|
657
|
+
# @param [Hash] options
|
658
|
+
# The HTTP options to merge into.
|
659
|
+
#
|
660
|
+
# @return [Hash]
|
661
|
+
# The merged HTTP options.
|
662
|
+
#
|
663
|
+
# @since 1.0.0
|
664
|
+
#
|
665
|
+
# @api private
|
666
|
+
#
|
667
|
+
def http_merge_options(options={})
|
668
|
+
options[:host] ||= self.host if self.host
|
669
|
+
options[:port] ||= self.port if self.port
|
670
|
+
|
671
|
+
if (self.http_vhost || self.http_user_agent)
|
672
|
+
headers = options.fetch(:headers,{})
|
673
|
+
|
674
|
+
headers[:host] ||= self.http_vhost if self.http_vhost
|
675
|
+
headers[:user_agent] ||= self.http_user_agent if self.http_user_agent
|
676
|
+
|
677
|
+
options[:headers] = headers
|
678
|
+
end
|
679
|
+
|
680
|
+
options[:user] ||= self.http_user if self.http_user
|
681
|
+
options[:password] ||= self.http_password if self.http_password
|
682
|
+
|
683
|
+
options[:proxy] ||= self.http_proxy if self.http_proxy
|
684
|
+
|
685
|
+
return options
|
686
|
+
end
|
687
|
+
|
688
|
+
#
|
689
|
+
# Converts the HTTP options to a printable String.
|
690
|
+
#
|
691
|
+
# @param [Hash] options
|
692
|
+
# HTTP options.
|
693
|
+
#
|
694
|
+
# @return [String]
|
695
|
+
# The printable String.
|
696
|
+
#
|
697
|
+
# @since 1.1.0
|
698
|
+
#
|
699
|
+
# @api private
|
700
|
+
#
|
701
|
+
def http_options_to_s(options)
|
702
|
+
fields = ["#{options[:host]}:#{options[:port]}"]
|
703
|
+
|
704
|
+
if (options[:user] || options[:password])
|
705
|
+
fields << "#{options[:user]}:#{options[:password]}"
|
706
|
+
end
|
707
|
+
|
708
|
+
path = options[:path]
|
709
|
+
path += "?#{options[:query]}" if options[:query]
|
710
|
+
|
711
|
+
fields << path
|
712
|
+
|
713
|
+
if options[:headers]
|
714
|
+
fields << ("%p" % options[:headers])
|
715
|
+
end
|
716
|
+
|
717
|
+
return fields.join(' ')
|
718
|
+
end
|
719
|
+
|
720
|
+
end
|
721
|
+
end
|
722
|
+
end
|
723
|
+
end
|