ronin-support 0.1.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +4 -0
- data/.rspec +1 -0
- data/.yardopts +1 -0
- data/COPYING.txt +504 -0
- data/ChangeLog.md +4 -0
- data/Gemfile +23 -0
- data/README.md +98 -0
- data/Rakefile +29 -0
- data/gemspec.yml +20 -0
- data/lib/ronin/extensions.rb +28 -0
- data/lib/ronin/extensions/file.rb +63 -0
- data/lib/ronin/extensions/ip_addr.rb +220 -0
- data/lib/ronin/extensions/kernel.rb +45 -0
- data/lib/ronin/extensions/meta.rb +22 -0
- data/lib/ronin/extensions/meta/object.rb +24 -0
- data/lib/ronin/extensions/string.rb +200 -0
- data/lib/ronin/formatting.rb +26 -0
- data/lib/ronin/formatting/binary.rb +22 -0
- data/lib/ronin/formatting/digest.rb +22 -0
- data/lib/ronin/formatting/extensions.rb +25 -0
- data/lib/ronin/formatting/extensions/binary.rb +24 -0
- data/lib/ronin/formatting/extensions/binary/file.rb +35 -0
- data/lib/ronin/formatting/extensions/binary/integer.rb +147 -0
- data/lib/ronin/formatting/extensions/binary/string.rb +363 -0
- data/lib/ronin/formatting/extensions/digest.rb +23 -0
- data/lib/ronin/formatting/extensions/digest/file.rb +117 -0
- data/lib/ronin/formatting/extensions/digest/string.rb +80 -0
- data/lib/ronin/formatting/extensions/http.rb +23 -0
- data/lib/ronin/formatting/extensions/http/integer.rb +57 -0
- data/lib/ronin/formatting/extensions/http/string.rb +102 -0
- data/lib/ronin/formatting/extensions/text.rb +23 -0
- data/lib/ronin/formatting/extensions/text/array.rb +125 -0
- data/lib/ronin/formatting/extensions/text/string.rb +206 -0
- data/lib/ronin/formatting/http.rb +22 -0
- data/lib/ronin/formatting/text.rb +22 -0
- data/lib/ronin/network.rb +29 -0
- data/lib/ronin/network/esmtp.rb +22 -0
- data/lib/ronin/network/extensions.rb +29 -0
- data/lib/ronin/network/extensions/esmtp.rb +22 -0
- data/lib/ronin/network/extensions/esmtp/net.rb +100 -0
- data/lib/ronin/network/extensions/http.rb +22 -0
- data/lib/ronin/network/extensions/http/net.rb +661 -0
- data/lib/ronin/network/extensions/imap.rb +22 -0
- data/lib/ronin/network/extensions/imap/net.rb +124 -0
- data/lib/ronin/network/extensions/pop3.rb +22 -0
- data/lib/ronin/network/extensions/pop3/net.rb +92 -0
- data/lib/ronin/network/extensions/smtp.rb +22 -0
- data/lib/ronin/network/extensions/smtp/net.rb +110 -0
- data/lib/ronin/network/extensions/ssl.rb +22 -0
- data/lib/ronin/network/extensions/ssl/net.rb +147 -0
- data/lib/ronin/network/extensions/tcp.rb +22 -0
- data/lib/ronin/network/extensions/tcp/net.rb +304 -0
- data/lib/ronin/network/extensions/telnet.rb +22 -0
- data/lib/ronin/network/extensions/telnet/net.rb +156 -0
- data/lib/ronin/network/extensions/udp.rb +22 -0
- data/lib/ronin/network/extensions/udp/net.rb +226 -0
- data/lib/ronin/network/http.rb +24 -0
- data/lib/ronin/network/http/exceptions.rb +22 -0
- data/lib/ronin/network/http/exceptions/unknown_request.rb +29 -0
- data/lib/ronin/network/http/http.rb +290 -0
- data/lib/ronin/network/http/proxy.rb +307 -0
- data/lib/ronin/network/imap.rb +49 -0
- data/lib/ronin/network/network.rb +41 -0
- data/lib/ronin/network/pop3.rb +49 -0
- data/lib/ronin/network/smtp.rb +24 -0
- data/lib/ronin/network/smtp/email.rb +143 -0
- data/lib/ronin/network/smtp/smtp.rb +68 -0
- data/lib/ronin/network/ssl.rb +47 -0
- data/lib/ronin/network/tcp.rb +22 -0
- data/lib/ronin/network/telnet.rb +109 -0
- data/lib/ronin/network/udp.rb +22 -0
- data/lib/ronin/path.rb +132 -0
- data/lib/ronin/support.rb +28 -0
- data/lib/ronin/support/inflector.rb +40 -0
- data/lib/ronin/support/version.rb +27 -0
- data/lib/ronin/templates.rb +23 -0
- data/lib/ronin/templates/erb.rb +75 -0
- data/lib/ronin/templates/template.rb +161 -0
- data/ronin-support.gemspec +10 -0
- data/spec/extensions/file_spec.rb +24 -0
- data/spec/extensions/ip_addr_spec.rb +171 -0
- data/spec/extensions/kernel_spec.rb +30 -0
- data/spec/extensions/string_spec.rb +177 -0
- data/spec/formatting/binary/helpers/hexdumps.rb +16 -0
- data/spec/formatting/binary/helpers/hexdumps/ascii.bin +0 -0
- data/spec/formatting/binary/helpers/hexdumps/hexdump_decimal_shorts.txt +17 -0
- data/spec/formatting/binary/helpers/hexdumps/hexdump_hex_bytes.txt +17 -0
- data/spec/formatting/binary/helpers/hexdumps/hexdump_hex_shorts.txt +17 -0
- data/spec/formatting/binary/helpers/hexdumps/hexdump_octal_bytes.txt +17 -0
- data/spec/formatting/binary/helpers/hexdumps/hexdump_octal_shorts.txt +17 -0
- data/spec/formatting/binary/helpers/hexdumps/hexdump_repeated.txt +6 -0
- data/spec/formatting/binary/helpers/hexdumps/od_decimal_bytes.txt +17 -0
- data/spec/formatting/binary/helpers/hexdumps/od_decimal_ints.txt +17 -0
- data/spec/formatting/binary/helpers/hexdumps/od_decimal_quads.txt +17 -0
- data/spec/formatting/binary/helpers/hexdumps/od_decimal_shorts.txt +17 -0
- data/spec/formatting/binary/helpers/hexdumps/od_hex_bytes.txt +17 -0
- data/spec/formatting/binary/helpers/hexdumps/od_hex_ints.txt +17 -0
- data/spec/formatting/binary/helpers/hexdumps/od_hex_quads.txt +17 -0
- data/spec/formatting/binary/helpers/hexdumps/od_hex_shorts.txt +17 -0
- data/spec/formatting/binary/helpers/hexdumps/od_octal_bytes.txt +17 -0
- data/spec/formatting/binary/helpers/hexdumps/od_octal_ints.txt +17 -0
- data/spec/formatting/binary/helpers/hexdumps/od_octal_quads.txt +17 -0
- data/spec/formatting/binary/helpers/hexdumps/od_octal_shorts.txt +17 -0
- data/spec/formatting/binary/helpers/hexdumps/od_repeated.txt +6 -0
- data/spec/formatting/binary/helpers/hexdumps/repeated.bin +1 -0
- data/spec/formatting/binary/integer_spec.rb +140 -0
- data/spec/formatting/binary/string_spec.rb +306 -0
- data/spec/formatting/digest/string_spec.rb +82 -0
- data/spec/formatting/http/integer_spec.rb +42 -0
- data/spec/formatting/http/string_spec.rb +76 -0
- data/spec/formatting/text/array_spec.rb +105 -0
- data/spec/formatting/text/string_spec.rb +180 -0
- data/spec/network/http/http_spec.rb +280 -0
- data/spec/network/http/proxy_spec.rb +150 -0
- data/spec/network/network_spec.rb +8 -0
- data/spec/network/ssl_spec.rb +14 -0
- data/spec/path_spec.rb +84 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/support_spec.rb +8 -0
- data/spec/templates/classes/example_erb.rb +11 -0
- data/spec/templates/classes/example_template.rb +35 -0
- data/spec/templates/erb_spec.rb +21 -0
- data/spec/templates/helpers/data.rb +9 -0
- data/spec/templates/helpers/data/includes/_relative.erb +1 -0
- data/spec/templates/helpers/data/templates/example.erb +1 -0
- data/spec/templates/template_spec.rb +54 -0
- metadata +286 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
#
|
2
|
+
# Ronin - A Ruby platform for exploit development and security research.
|
3
|
+
#
|
4
|
+
# Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
|
5
|
+
#
|
6
|
+
# This library is free software; you can redistribute it and/or
|
7
|
+
# modify it under the terms of the GNU Lesser General Public
|
8
|
+
# License as published by the Free Software Foundation; either
|
9
|
+
# version 2.1 of the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This library 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 GNU
|
14
|
+
# Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public
|
17
|
+
# License along with this library; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
19
|
+
# Boston, MA 02110-1301 USA
|
20
|
+
#
|
21
|
+
|
22
|
+
require 'ronin/network/extensions/http/net'
|
@@ -0,0 +1,661 @@
|
|
1
|
+
#
|
2
|
+
# Ronin - A Ruby platform for exploit development and security research.
|
3
|
+
#
|
4
|
+
# Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
|
5
|
+
#
|
6
|
+
# This library is free software; you can redistribute it and/or
|
7
|
+
# modify it under the terms of the GNU Lesser General Public
|
8
|
+
# License as published by the Free Software Foundation; either
|
9
|
+
# version 2.1 of the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This library 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 GNU
|
14
|
+
# Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public
|
17
|
+
# License along with this library; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
19
|
+
# Boston, MA 02110-1301 USA
|
20
|
+
#
|
21
|
+
|
22
|
+
require 'ronin/network/http'
|
23
|
+
require 'ronin/network/ssl'
|
24
|
+
|
25
|
+
require 'uri/query_params'
|
26
|
+
require 'net/http'
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'net/https'
|
30
|
+
rescue ::LoadError
|
31
|
+
end
|
32
|
+
|
33
|
+
module Net
|
34
|
+
#
|
35
|
+
# Starts a HTTP connection with the server.
|
36
|
+
#
|
37
|
+
# @param [Hash] options
|
38
|
+
# Additional options
|
39
|
+
#
|
40
|
+
# @option options [String, URI::HTTP] :url
|
41
|
+
# The full URL to request.
|
42
|
+
#
|
43
|
+
# @option options [String] :host
|
44
|
+
# The host the HTTP server is running on.
|
45
|
+
#
|
46
|
+
# @option options [Integer] :port (Net::HTTP.default_port)
|
47
|
+
# The port the HTTP server is listening on.
|
48
|
+
#
|
49
|
+
# @option options [String, Hash] :proxy (Ronin::Network::HTTP.proxy)
|
50
|
+
# A Hash of proxy settings to use when connecting to the HTTP server.
|
51
|
+
#
|
52
|
+
# @option options [String] :user
|
53
|
+
# The user to authenticate with when connecting to the HTTP server.
|
54
|
+
#
|
55
|
+
# @option options [String] :password
|
56
|
+
# The password to authenticate with when connecting to the HTTP server.
|
57
|
+
#
|
58
|
+
# @option options [Boolean, Hash] :ssl
|
59
|
+
# Enables SSL for the HTTP connection.
|
60
|
+
#
|
61
|
+
# @option :ssl [Symbol] :verify
|
62
|
+
# Specifies the SSL certificate verification mode.
|
63
|
+
#
|
64
|
+
# @yield [session]
|
65
|
+
# If a block is given, it will be passed the newly created HTTP
|
66
|
+
# session object.
|
67
|
+
#
|
68
|
+
# @yieldparam [Net::HTTP] session
|
69
|
+
# The newly created HTTP session.
|
70
|
+
#
|
71
|
+
# @return [Net::HTTP]
|
72
|
+
# The HTTP session object.
|
73
|
+
#
|
74
|
+
def Net.http_connect(options={},&block)
|
75
|
+
options = Ronin::Network::HTTP.expand_options(options)
|
76
|
+
|
77
|
+
host = options[:host].to_s
|
78
|
+
port = options[:port]
|
79
|
+
proxy = options[:proxy]
|
80
|
+
proxy_host = if (proxy && proxy[:host])
|
81
|
+
proxy[:host].to_s
|
82
|
+
end
|
83
|
+
|
84
|
+
sess = Net::HTTP::Proxy(
|
85
|
+
proxy_host,
|
86
|
+
proxy[:port],
|
87
|
+
proxy[:user],
|
88
|
+
proxy[:password]
|
89
|
+
).new(host.to_s,port)
|
90
|
+
|
91
|
+
if options[:ssl]
|
92
|
+
sess.use_ssl = true
|
93
|
+
sess.verify_mode = Ronin::Network::SSL.verify(options[:ssl][:verify])
|
94
|
+
end
|
95
|
+
|
96
|
+
sess.start()
|
97
|
+
|
98
|
+
if block
|
99
|
+
if block.arity == 2
|
100
|
+
block.call(sess,options)
|
101
|
+
else
|
102
|
+
block.call(sess)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
return sess
|
107
|
+
end
|
108
|
+
|
109
|
+
#
|
110
|
+
# Creates a new temporary HTTP session with the server.
|
111
|
+
#
|
112
|
+
# @param [Hash] options
|
113
|
+
# Additional options
|
114
|
+
#
|
115
|
+
# @option options [String, URI::HTTP] :url
|
116
|
+
# The full URL to request.
|
117
|
+
#
|
118
|
+
# @option options [String] :host
|
119
|
+
# The host the HTTP server is running on.
|
120
|
+
#
|
121
|
+
# @option options [Integer] :port (Net::HTTP.default_port)
|
122
|
+
# The port the HTTP server is listening on.
|
123
|
+
#
|
124
|
+
# @option options [String] :user
|
125
|
+
# The user to authenticate with when connecting to the HTTP server.
|
126
|
+
#
|
127
|
+
# @option options [String] :password
|
128
|
+
# The password to authenticate with when connecting to the HTTP server.
|
129
|
+
#
|
130
|
+
# @option options [String, Hash] :proxy (Ronin::Network::HTTP.proxy)
|
131
|
+
# A Hash of proxy settings to use when connecting to the HTTP server.
|
132
|
+
#
|
133
|
+
# @option options [Boolean, Hash] :ssl
|
134
|
+
# Enables SSL for the HTTP connection.
|
135
|
+
#
|
136
|
+
# @option :ssl [Symbol] :verify
|
137
|
+
# Specifies the SSL certificate verification mode.
|
138
|
+
#
|
139
|
+
# @yield [session]
|
140
|
+
# If a block is given, it will be passed the newly created HTTP
|
141
|
+
# session object.
|
142
|
+
#
|
143
|
+
# @yieldparam [Net::HTTP] session
|
144
|
+
# The newly created HTTP session.
|
145
|
+
#
|
146
|
+
# @return [nil]
|
147
|
+
#
|
148
|
+
# @see Net.http_connect
|
149
|
+
#
|
150
|
+
def Net.http_session(options={},&block)
|
151
|
+
Net.http_connect(options) do |sess,expanded_options|
|
152
|
+
if block
|
153
|
+
if block.arity == 2
|
154
|
+
block.call(sess,expanded_options)
|
155
|
+
else
|
156
|
+
block.call(sess)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
sess.finish
|
161
|
+
end
|
162
|
+
|
163
|
+
return nil
|
164
|
+
end
|
165
|
+
|
166
|
+
#
|
167
|
+
# Connects to the HTTP server and sends an HTTP Request.
|
168
|
+
#
|
169
|
+
# @param [Hash] options
|
170
|
+
# Additional options.
|
171
|
+
#
|
172
|
+
# @option options [Symbol, String] :method
|
173
|
+
# The HTTP method to use in the request.
|
174
|
+
#
|
175
|
+
# @option options [String] :path
|
176
|
+
# The path to request from the HTTP server.
|
177
|
+
#
|
178
|
+
# @option options [Hash] :headers
|
179
|
+
# The Hash of the HTTP headers to send with the request.
|
180
|
+
# May contain either Strings or Symbols, lower-case or camel-case keys.
|
181
|
+
#
|
182
|
+
# @yield [request, (options)]
|
183
|
+
# If a block is given, it will be passed the HTTP request object.
|
184
|
+
# If the block has an arity of 2, it will also be passed the expanded
|
185
|
+
# version of the given _options_.
|
186
|
+
#
|
187
|
+
# @yieldparam [Net::HTTP::Request] request
|
188
|
+
# The HTTP request object to use in the request.
|
189
|
+
#
|
190
|
+
# @yieldparam [Hash] options
|
191
|
+
# The expanded version of the given _options_.
|
192
|
+
#
|
193
|
+
# @return [Net::HTTP::Response]
|
194
|
+
# The response of the HTTP request.
|
195
|
+
#
|
196
|
+
# @see http_session
|
197
|
+
#
|
198
|
+
def Net.http_request(options={},&block)
|
199
|
+
resp = nil
|
200
|
+
|
201
|
+
Net.http_session(options) do |http,expanded_options|
|
202
|
+
req = Ronin::Network::HTTP.request(expanded_options)
|
203
|
+
|
204
|
+
if block
|
205
|
+
if block.arity == 2
|
206
|
+
block.call(req,expanded_options)
|
207
|
+
else
|
208
|
+
block.call(req)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
resp = http.request(req)
|
213
|
+
end
|
214
|
+
|
215
|
+
return resp
|
216
|
+
end
|
217
|
+
|
218
|
+
#
|
219
|
+
# Performs an HTTP Copy request.
|
220
|
+
#
|
221
|
+
# @param [Hash] options
|
222
|
+
# Additional options.
|
223
|
+
#
|
224
|
+
# @yield [response]
|
225
|
+
# If a block is given, it will be passed the response received
|
226
|
+
# from the request.
|
227
|
+
#
|
228
|
+
# @yieldparam [Net::HTTP::Response] response
|
229
|
+
# The HTTP response object.
|
230
|
+
#
|
231
|
+
# @return [Net::HTTP::Response]
|
232
|
+
# The response of the HTTP request.
|
233
|
+
#
|
234
|
+
# @see http_request
|
235
|
+
#
|
236
|
+
def Net.http_copy(options={})
|
237
|
+
resp = Net.http_request(options.merge(:method => :copy))
|
238
|
+
|
239
|
+
yield resp if block_given?
|
240
|
+
return resp
|
241
|
+
end
|
242
|
+
|
243
|
+
#
|
244
|
+
# Performs an HTTP Delete request.
|
245
|
+
#
|
246
|
+
# @param [Hash] options
|
247
|
+
# Additional options.
|
248
|
+
#
|
249
|
+
# @yield [response]
|
250
|
+
# If a block is given, it will be passed the response received from
|
251
|
+
# the request.
|
252
|
+
#
|
253
|
+
# @yieldparam [Net::HTTP::Response] response
|
254
|
+
# The HTTP response object.
|
255
|
+
#
|
256
|
+
# @return [Net::HTTP::Response]
|
257
|
+
# The response of the HTTP request.
|
258
|
+
#
|
259
|
+
# @see http_request
|
260
|
+
#
|
261
|
+
def Net.http_delete(options={},&block)
|
262
|
+
original_headers = options[:headers]
|
263
|
+
|
264
|
+
# set the HTTP Depth header
|
265
|
+
options[:headers] = {:depth => 'Infinity'}
|
266
|
+
|
267
|
+
if original_headers
|
268
|
+
options[:header].merge!(original_headers)
|
269
|
+
end
|
270
|
+
|
271
|
+
resp = Net.http_request(options.merge(:method => :delete))
|
272
|
+
|
273
|
+
yield resp if block_given?
|
274
|
+
return resp
|
275
|
+
end
|
276
|
+
|
277
|
+
#
|
278
|
+
# Performs an HTTP Get request.
|
279
|
+
#
|
280
|
+
# @param [Hash] options
|
281
|
+
# Additional options.
|
282
|
+
#
|
283
|
+
# @yield [response]
|
284
|
+
# If a block is given, it will be passed the response received from
|
285
|
+
# the request.
|
286
|
+
#
|
287
|
+
# @yieldparam [Net::HTTP::Response] response
|
288
|
+
# The HTTP response object.
|
289
|
+
#
|
290
|
+
# @return [Net::HTTP::Response]
|
291
|
+
# The response of the HTTP request.
|
292
|
+
#
|
293
|
+
# @see http_request
|
294
|
+
#
|
295
|
+
def Net.http_get(options={},&block)
|
296
|
+
resp = Net.http_request(options.merge(:method => :get))
|
297
|
+
|
298
|
+
yield resp if block_given?
|
299
|
+
return resp
|
300
|
+
end
|
301
|
+
|
302
|
+
#
|
303
|
+
# Performs an HTTP Get request.
|
304
|
+
#
|
305
|
+
# @param [Hash] options
|
306
|
+
# Additional options.
|
307
|
+
#
|
308
|
+
# @yield [response]
|
309
|
+
# If a block is given, it will be passed the response received from
|
310
|
+
# the request.
|
311
|
+
#
|
312
|
+
# @yieldparam [Net::HTTP::Response] response
|
313
|
+
# The HTTP response object.
|
314
|
+
#
|
315
|
+
# @return [String]
|
316
|
+
# The body of the HTTP response.
|
317
|
+
#
|
318
|
+
# @see http_request
|
319
|
+
#
|
320
|
+
def Net.http_get_body(options={},&block)
|
321
|
+
Net.http_get(options,&block).body
|
322
|
+
end
|
323
|
+
|
324
|
+
#
|
325
|
+
# Performs an HTTP Head request.
|
326
|
+
#
|
327
|
+
# @param [Hash] options
|
328
|
+
# Additional options.
|
329
|
+
#
|
330
|
+
# @yield [response]
|
331
|
+
# If a block is given, it will be passed the response received from
|
332
|
+
# the request.
|
333
|
+
#
|
334
|
+
# @yieldparam [Net::HTTP::Response] response
|
335
|
+
# The HTTP response object.
|
336
|
+
#
|
337
|
+
# @return [Net::HTTP::Response]
|
338
|
+
# The response of the HTTP request.
|
339
|
+
#
|
340
|
+
# @see http_request
|
341
|
+
#
|
342
|
+
def Net.http_head(options={},&block)
|
343
|
+
resp = Net.http_request(options.merge(:method => :head))
|
344
|
+
|
345
|
+
yield resp if block_given?
|
346
|
+
return resp
|
347
|
+
end
|
348
|
+
|
349
|
+
#
|
350
|
+
# Checks if the response has an HTTP OK status code.
|
351
|
+
#
|
352
|
+
# @param [Hash] options
|
353
|
+
# Additional options.
|
354
|
+
#
|
355
|
+
# @return [Boolean]
|
356
|
+
# Specifies wether the response had an HTTP OK status code or not.
|
357
|
+
#
|
358
|
+
# @see http_request
|
359
|
+
#
|
360
|
+
def Net.http_ok?(options={})
|
361
|
+
Net.http_head(options).code == 200
|
362
|
+
end
|
363
|
+
|
364
|
+
#
|
365
|
+
# Sends a HTTP Head request and returns the HTTP Server header.
|
366
|
+
#
|
367
|
+
# @param [Hash] options
|
368
|
+
# Additional options.
|
369
|
+
#
|
370
|
+
# @return [String]
|
371
|
+
# The HTTP `Server` header.
|
372
|
+
#
|
373
|
+
# @see http_request
|
374
|
+
#
|
375
|
+
def Net.http_server(options={})
|
376
|
+
Net.http_head(options)['server']
|
377
|
+
end
|
378
|
+
|
379
|
+
#
|
380
|
+
# Sends an HTTP Head request and returns the HTTP X-Powered-By header.
|
381
|
+
#
|
382
|
+
# @param [Hash] options
|
383
|
+
# Additional options.
|
384
|
+
#
|
385
|
+
# @return [String]
|
386
|
+
# The HTTP `X-Powered-By` header.
|
387
|
+
#
|
388
|
+
# @see http_request
|
389
|
+
#
|
390
|
+
def Net.http_powered_by(options={})
|
391
|
+
resp = Net.http_head(options)
|
392
|
+
|
393
|
+
if resp.code != 200
|
394
|
+
resp = Net.http_get(options)
|
395
|
+
end
|
396
|
+
|
397
|
+
return resp['x-powered-by']
|
398
|
+
end
|
399
|
+
|
400
|
+
#
|
401
|
+
# Performs an HTTP Lock request.
|
402
|
+
#
|
403
|
+
# @param [Hash] options
|
404
|
+
# Additional options.
|
405
|
+
#
|
406
|
+
# @yield [response]
|
407
|
+
# If a block is given, it will be passed the response received from
|
408
|
+
# the request.
|
409
|
+
#
|
410
|
+
# @yieldparam [Net::HTTP::Response] response
|
411
|
+
# The HTTP response object.
|
412
|
+
#
|
413
|
+
# @return [Net::HTTP::Response]
|
414
|
+
# The response of the HTTP request.
|
415
|
+
#
|
416
|
+
# @see http_request
|
417
|
+
#
|
418
|
+
def Net.http_lock(options={},&block)
|
419
|
+
resp = Net.http_request(options.merge(:method => :lock))
|
420
|
+
|
421
|
+
yield resp if block_given?
|
422
|
+
return resp
|
423
|
+
end
|
424
|
+
|
425
|
+
#
|
426
|
+
# Performs an HTTP Mkcol request.
|
427
|
+
#
|
428
|
+
# @param [Hash] options
|
429
|
+
# Additional options.
|
430
|
+
#
|
431
|
+
# @yield [response]
|
432
|
+
# If a block is given, it will be passed the response received from
|
433
|
+
# the request.
|
434
|
+
#
|
435
|
+
# @yieldparam [Net::HTTP::Response] response
|
436
|
+
# The HTTP response object.
|
437
|
+
#
|
438
|
+
# @return [Net::HTTP::Response]
|
439
|
+
# The response of the HTTP request.
|
440
|
+
#
|
441
|
+
# @see http_request
|
442
|
+
#
|
443
|
+
def Net.http_mkcol(options={},&block)
|
444
|
+
resp = Net.http_request(options.merge(:method => :mkcol))
|
445
|
+
|
446
|
+
yield resp if block_given?
|
447
|
+
return resp
|
448
|
+
end
|
449
|
+
|
450
|
+
#
|
451
|
+
# Performs an HTTP Move request.
|
452
|
+
#
|
453
|
+
# @param [Hash] options
|
454
|
+
# Additional options.
|
455
|
+
#
|
456
|
+
# @yield [response]
|
457
|
+
# If a block is given, it will be passed the response received from
|
458
|
+
# the request.
|
459
|
+
#
|
460
|
+
# @yieldparam [Net::HTTP::Response] response
|
461
|
+
# The HTTP response object.
|
462
|
+
#
|
463
|
+
# @return [Net::HTTP::Response]
|
464
|
+
# The response of the HTTP request.
|
465
|
+
#
|
466
|
+
# @see http_request
|
467
|
+
#
|
468
|
+
def Net.http_move(options={},&block)
|
469
|
+
resp = Net.http_request(options.merge(:method => :move))
|
470
|
+
|
471
|
+
yield resp if block_given?
|
472
|
+
return resp
|
473
|
+
end
|
474
|
+
|
475
|
+
#
|
476
|
+
# Performs an HTTP Options request.
|
477
|
+
#
|
478
|
+
# @param [Hash] options
|
479
|
+
# Additional options.
|
480
|
+
#
|
481
|
+
# @yield [response]
|
482
|
+
# If a block is given, it will be passed the response received from
|
483
|
+
# 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
|
+
def Net.http_options(options={},&block)
|
494
|
+
resp = Net.http_request(options.merge(:method => :options))
|
495
|
+
|
496
|
+
yield resp if block_given?
|
497
|
+
return resp
|
498
|
+
end
|
499
|
+
|
500
|
+
#
|
501
|
+
# Performs an HTTP Post request.
|
502
|
+
#
|
503
|
+
# @param [Hash] options
|
504
|
+
# Additional options.
|
505
|
+
#
|
506
|
+
# @option options [Hash, String] :form_data
|
507
|
+
# The form data to send with the HTTP Post request.
|
508
|
+
#
|
509
|
+
# @yield [response]
|
510
|
+
# If a block is given, it will be passed the response received from
|
511
|
+
# the request.
|
512
|
+
#
|
513
|
+
# @yieldparam [Net::HTTP::Response] response
|
514
|
+
# The HTTP response object.
|
515
|
+
#
|
516
|
+
# @return [Net::HTTP::Response]
|
517
|
+
# The response of the HTTP request.
|
518
|
+
#
|
519
|
+
# @see http_request
|
520
|
+
#
|
521
|
+
def Net.http_post(options={},&block)
|
522
|
+
resp = Net.http_request(options.merge(:method => :post))
|
523
|
+
|
524
|
+
yield resp if block_given?
|
525
|
+
return resp
|
526
|
+
end
|
527
|
+
|
528
|
+
#
|
529
|
+
# Performs an HTTP Post request.
|
530
|
+
#
|
531
|
+
# @param [Hash] options
|
532
|
+
# Additional options.
|
533
|
+
#
|
534
|
+
# @option options [Hash, String] :form_data
|
535
|
+
# The form data to send with the HTTP Post request.
|
536
|
+
#
|
537
|
+
# @yield [response]
|
538
|
+
# If a block is given, it will be passed the response received from
|
539
|
+
# the request.
|
540
|
+
#
|
541
|
+
# @yieldparam [Net::HTTP::Response] response
|
542
|
+
# The HTTP response object.
|
543
|
+
#
|
544
|
+
# @return [String]
|
545
|
+
# The body of the HTTP response.
|
546
|
+
#
|
547
|
+
# @see http_request
|
548
|
+
#
|
549
|
+
def Net.http_post_body(options={},&block)
|
550
|
+
Net.http_post(options,&block).body
|
551
|
+
end
|
552
|
+
|
553
|
+
#
|
554
|
+
# Performs an HTTP Propfind request.
|
555
|
+
#
|
556
|
+
# @param [Hash] options
|
557
|
+
# Additional options.
|
558
|
+
#
|
559
|
+
# @yield [response]
|
560
|
+
# If a block is given, it will be passed the response received from
|
561
|
+
# 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
|
+
def Net.http_prop_find(options={},&block)
|
572
|
+
original_headers = options[:headers]
|
573
|
+
|
574
|
+
# set the HTTP Depth header
|
575
|
+
options[:headers] = {:depth => '0'}
|
576
|
+
|
577
|
+
if original_headers
|
578
|
+
options[:header].merge!(original_headers)
|
579
|
+
end
|
580
|
+
|
581
|
+
resp = Net.http_request(options.merge(:method => :propfind))
|
582
|
+
|
583
|
+
yield resp if block_given?
|
584
|
+
return resp
|
585
|
+
end
|
586
|
+
|
587
|
+
#
|
588
|
+
# Performs an HTTP Proppatch request.
|
589
|
+
#
|
590
|
+
# @param [Hash] options
|
591
|
+
# Additional options.
|
592
|
+
#
|
593
|
+
# @yield [response]
|
594
|
+
# If a block is given, it will be passed the response received from
|
595
|
+
# the request.
|
596
|
+
#
|
597
|
+
# @yieldparam [Net::HTTP::Response] response
|
598
|
+
# The HTTP response object.
|
599
|
+
#
|
600
|
+
# @return [Net::HTTP::Response]
|
601
|
+
# The response of the HTTP request.
|
602
|
+
#
|
603
|
+
# @see http_request
|
604
|
+
#
|
605
|
+
def Net.http_prop_patch(options={},&block)
|
606
|
+
resp = Net.http_request(options.merge(:method => :proppatch))
|
607
|
+
|
608
|
+
yield resp if block_given?
|
609
|
+
return resp
|
610
|
+
end
|
611
|
+
|
612
|
+
#
|
613
|
+
# Performs an HTTP Trace request.
|
614
|
+
#
|
615
|
+
# @param [Hash] options
|
616
|
+
# Additional options.
|
617
|
+
#
|
618
|
+
# @yield [response]
|
619
|
+
# If a block is given, it will be passed the response received from
|
620
|
+
# the request.
|
621
|
+
#
|
622
|
+
# @yieldparam [Net::HTTP::Response] response
|
623
|
+
# The HTTP response object.
|
624
|
+
#
|
625
|
+
# @return [Net::HTTP::Response]
|
626
|
+
# The response of the HTTP request.
|
627
|
+
#
|
628
|
+
# @see http_request
|
629
|
+
#
|
630
|
+
def Net.http_trace(options={},&block)
|
631
|
+
resp = Net.http_request(options.merge(:method => :trace))
|
632
|
+
|
633
|
+
yield resp if block_given?
|
634
|
+
return resp
|
635
|
+
end
|
636
|
+
|
637
|
+
#
|
638
|
+
# Performs an HTTP Unlock request.
|
639
|
+
#
|
640
|
+
# @param [Hash] options
|
641
|
+
# Additional options.
|
642
|
+
#
|
643
|
+
# @yield [response]
|
644
|
+
# If a block is given, it will be passed the response received from
|
645
|
+
# the request.
|
646
|
+
#
|
647
|
+
# @yieldparam [Net::HTTP::Response] response
|
648
|
+
# The HTTP response object.
|
649
|
+
#
|
650
|
+
# @return [Net::HTTP::Response]
|
651
|
+
# The response of the HTTP request.
|
652
|
+
#
|
653
|
+
# @see http_request
|
654
|
+
#
|
655
|
+
def Net.http_unlock(options={},&block)
|
656
|
+
resp = Net.http_request(options.merge(:method => :unlock))
|
657
|
+
|
658
|
+
yield resp if block_given?
|
659
|
+
return resp
|
660
|
+
end
|
661
|
+
end
|