mechanize 2.0.1 → 2.1.pre.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of mechanize might be problematic. Click here for more details.
- data.tar.gz.sig +0 -0
- data/CHANGELOG.rdoc +82 -0
- data/EXAMPLES.rdoc +1 -1
- data/FAQ.rdoc +9 -9
- data/Manifest.txt +35 -48
- data/README.rdoc +2 -1
- data/Rakefile +16 -3
- data/lib/mechanize.rb +809 -392
- data/lib/mechanize/content_type_error.rb +10 -11
- data/lib/mechanize/cookie.rb +193 -60
- data/lib/mechanize/cookie_jar.rb +39 -86
- data/lib/mechanize/download.rb +59 -0
- data/lib/mechanize/element_matcher.rb +1 -0
- data/lib/mechanize/file.rb +61 -76
- data/lib/mechanize/file_saver.rb +37 -35
- data/lib/mechanize/form.rb +475 -410
- data/lib/mechanize/form/button.rb +4 -7
- data/lib/mechanize/form/check_box.rb +10 -9
- data/lib/mechanize/form/field.rb +52 -42
- data/lib/mechanize/form/file_upload.rb +17 -19
- data/lib/mechanize/form/hidden.rb +3 -0
- data/lib/mechanize/form/image_button.rb +15 -16
- data/lib/mechanize/form/keygen.rb +34 -0
- data/lib/mechanize/form/multi_select_list.rb +20 -9
- data/lib/mechanize/form/option.rb +48 -47
- data/lib/mechanize/form/radio_button.rb +52 -45
- data/lib/mechanize/form/reset.rb +3 -0
- data/lib/mechanize/form/select_list.rb +10 -6
- data/lib/mechanize/form/submit.rb +3 -0
- data/lib/mechanize/form/text.rb +3 -0
- data/lib/mechanize/form/textarea.rb +3 -0
- data/lib/mechanize/headers.rb +17 -19
- data/lib/mechanize/history.rb +60 -61
- data/lib/mechanize/http.rb +5 -0
- data/lib/mechanize/http/agent.rb +485 -218
- data/lib/mechanize/http/auth_challenge.rb +59 -0
- data/lib/mechanize/http/auth_realm.rb +31 -0
- data/lib/mechanize/http/content_disposition_parser.rb +188 -0
- data/lib/mechanize/http/www_authenticate_parser.rb +155 -0
- data/lib/mechanize/monkey_patch.rb +14 -35
- data/lib/mechanize/page.rb +34 -2
- data/lib/mechanize/page/base.rb +6 -7
- data/lib/mechanize/page/frame.rb +5 -5
- data/lib/mechanize/page/image.rb +23 -23
- data/lib/mechanize/page/label.rb +16 -16
- data/lib/mechanize/page/link.rb +16 -0
- data/lib/mechanize/page/meta_refresh.rb +19 -7
- data/lib/mechanize/parser.rb +173 -0
- data/lib/mechanize/pluggable_parsers.rb +126 -83
- data/lib/mechanize/redirect_limit_reached_error.rb +16 -13
- data/lib/mechanize/redirect_not_get_or_head_error.rb +18 -16
- data/lib/mechanize/response_code_error.rb +16 -17
- data/lib/mechanize/robots_disallowed_error.rb +22 -23
- data/lib/mechanize/test_case.rb +659 -0
- data/lib/mechanize/unauthorized_error.rb +3 -0
- data/lib/mechanize/unsupported_scheme_error.rb +4 -6
- data/lib/mechanize/util.rb +0 -12
- data/test/htdocs/form_order_test.html +11 -0
- data/test/htdocs/form_test.html +2 -2
- data/test/htdocs/tc_links.html +1 -0
- data/test/test_mechanize.rb +367 -59
- data/test/test_mechanize_cookie.rb +69 -4
- data/test/test_mechanize_cookie_jar.rb +200 -124
- data/test/test_mechanize_download.rb +43 -0
- data/test/test_mechanize_file.rb +53 -45
- data/test/{test_mechanize_file_response.rb → test_mechanize_file_connection.rb} +2 -2
- data/test/test_mechanize_file_request.rb +2 -2
- data/test/test_mechanize_file_saver.rb +21 -0
- data/test/test_mechanize_form.rb +345 -46
- data/test/test_mechanize_form_check_box.rb +5 -4
- data/test/test_mechanize_form_encoding.rb +10 -16
- data/test/test_mechanize_form_field.rb +45 -3
- data/test/test_mechanize_form_file_upload.rb +20 -0
- data/test/test_mechanize_form_image_button.rb +2 -2
- data/test/test_mechanize_form_keygen.rb +32 -0
- data/test/test_mechanize_form_multi_select_list.rb +84 -0
- data/test/test_mechanize_form_option.rb +55 -0
- data/test/test_mechanize_form_radio_button.rb +78 -0
- data/test/test_mechanize_form_select_list.rb +76 -0
- data/test/test_mechanize_form_textarea.rb +8 -7
- data/test/{test_headers.rb → test_mechanize_headers.rb} +4 -2
- data/test/test_mechanize_history.rb +103 -0
- data/test/test_mechanize_http_agent.rb +525 -17
- data/test/test_mechanize_http_auth_challenge.rb +39 -0
- data/test/test_mechanize_http_auth_realm.rb +49 -0
- data/test/test_mechanize_http_content_disposition_parser.rb +118 -0
- data/test/test_mechanize_http_www_authenticate_parser.rb +146 -0
- data/test/test_mechanize_link.rb +10 -14
- data/test/test_mechanize_page.rb +118 -0
- data/test/test_mechanize_page_encoding.rb +48 -13
- data/test/test_mechanize_page_frame.rb +16 -0
- data/test/test_mechanize_page_link.rb +27 -19
- data/test/test_mechanize_page_meta_refresh.rb +26 -14
- data/test/test_mechanize_parser.rb +289 -0
- data/test/test_mechanize_pluggable_parser.rb +52 -0
- data/test/test_mechanize_redirect_limit_reached_error.rb +24 -0
- data/test/test_mechanize_redirect_not_get_or_head_error.rb +3 -7
- data/test/test_mechanize_subclass.rb +2 -2
- data/test/test_mechanize_util.rb +24 -13
- data/test/test_multi_select.rb +23 -22
- metadata +145 -114
- metadata.gz.sig +0 -0
- data/lib/mechanize/inspect.rb +0 -88
- data/test/helper.rb +0 -175
- data/test/htdocs/form_select_all.html +0 -16
- data/test/htdocs/form_select_none.html +0 -17
- data/test/htdocs/form_select_noopts.html +0 -10
- data/test/htdocs/iframe_test.html +0 -16
- data/test/htdocs/nofollow.html +0 -9
- data/test/htdocs/norobots.html +0 -8
- data/test/htdocs/rel_nofollow.html +0 -8
- data/test/htdocs/tc_base_images.html +0 -10
- data/test/htdocs/tc_images.html +0 -8
- data/test/htdocs/tc_no_attributes.html +0 -16
- data/test/htdocs/tc_radiobuttons.html +0 -17
- data/test/htdocs/test_bad_encoding.html +0 -52
- data/test/servlets.rb +0 -402
- data/test/ssl_server.rb +0 -48
- data/test/test_cookies.rb +0 -129
- data/test/test_form_action.rb +0 -52
- data/test/test_form_as_hash.rb +0 -59
- data/test/test_form_button.rb +0 -46
- data/test/test_frames.rb +0 -34
- data/test/test_history.rb +0 -118
- data/test/test_history_added.rb +0 -16
- data/test/test_html_unscape_forms.rb +0 -46
- data/test/test_if_modified_since.rb +0 -20
- data/test/test_images.rb +0 -19
- data/test/test_no_attributes.rb +0 -13
- data/test/test_option.rb +0 -18
- data/test/test_pluggable_parser.rb +0 -136
- data/test/test_post_form.rb +0 -37
- data/test/test_pretty_print.rb +0 -22
- data/test/test_radiobutton.rb +0 -75
- data/test/test_redirect_limit_reached.rb +0 -39
- data/test/test_referer.rb +0 -81
- data/test/test_relative_links.rb +0 -40
- data/test/test_request.rb +0 -13
- data/test/test_response_code.rb +0 -53
- data/test/test_robots.rb +0 -72
- data/test/test_save_file.rb +0 -48
- data/test/test_scheme.rb +0 -48
- data/test/test_select.rb +0 -119
- data/test/test_select_all.rb +0 -15
- data/test/test_select_none.rb +0 -15
- data/test/test_select_noopts.rb +0 -18
- data/test/test_set_fields.rb +0 -44
- data/test/test_ssl_server.rb +0 -20
data/test/servlets.rb
DELETED
@@ -1,402 +0,0 @@
|
|
1
|
-
require 'webrick'
|
2
|
-
require 'logger'
|
3
|
-
require 'date'
|
4
|
-
require 'zlib'
|
5
|
-
require 'stringio'
|
6
|
-
require 'base64'
|
7
|
-
|
8
|
-
class VerbServlet < WEBrick::HTTPServlet::AbstractServlet
|
9
|
-
%w(HEAD GET POST PUT DELETE).each do |verb|
|
10
|
-
eval(<<-eomethod)
|
11
|
-
def do_#{verb}(req, res)
|
12
|
-
res.header['X-Request-Method'] = #{verb.dump}
|
13
|
-
end
|
14
|
-
eomethod
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class BasicAuthServlet < WEBrick::HTTPServlet::AbstractServlet
|
19
|
-
def do_GET(req,res)
|
20
|
-
htpd = WEBrick::HTTPAuth::Htpasswd.new('dot.htpasswd')
|
21
|
-
htpd.set_passwd('Blah', 'user', 'pass')
|
22
|
-
authenticator = WEBrick::HTTPAuth::BasicAuth.new({
|
23
|
-
:UserDB => htpd,
|
24
|
-
:Realm => 'Blah',
|
25
|
-
:Logger => Logger.new(nil)
|
26
|
-
}
|
27
|
-
)
|
28
|
-
begin
|
29
|
-
authenticator.authenticate(req,res)
|
30
|
-
res.body = 'You are authenticated'
|
31
|
-
rescue WEBrick::HTTPStatus::Unauthorized
|
32
|
-
res.status = 401
|
33
|
-
end
|
34
|
-
FileUtils.rm('dot.htpasswd')
|
35
|
-
end
|
36
|
-
alias :do_POST :do_GET
|
37
|
-
end
|
38
|
-
|
39
|
-
class DigestAuthServlet < WEBrick::HTTPServlet::AbstractServlet
|
40
|
-
htpd = WEBrick::HTTPAuth::Htdigest.new('digest.htpasswd')
|
41
|
-
htpd.set_passwd('Blah', 'user', 'pass')
|
42
|
-
@@authenticator = WEBrick::HTTPAuth::DigestAuth.new({
|
43
|
-
:UserDB => htpd,
|
44
|
-
:Realm => 'Blah',
|
45
|
-
:Algorithm => 'MD5',
|
46
|
-
:Logger => Logger.new(nil)
|
47
|
-
}
|
48
|
-
)
|
49
|
-
def do_GET(req,res)
|
50
|
-
def req.request_time; Time.now; end
|
51
|
-
def req.request_uri; '/digest_auth'; end
|
52
|
-
def req.request_method; "GET"; end
|
53
|
-
|
54
|
-
begin
|
55
|
-
@@authenticator.authenticate(req,res)
|
56
|
-
res.body = 'You are authenticated'
|
57
|
-
rescue WEBrick::HTTPStatus::Unauthorized
|
58
|
-
res.status = 401
|
59
|
-
end
|
60
|
-
FileUtils.rm('digest.htpasswd') if File.exists?('digest.htpasswd')
|
61
|
-
end
|
62
|
-
alias :do_POST :do_GET
|
63
|
-
end
|
64
|
-
|
65
|
-
class HeaderServlet < WEBrick::HTTPServlet::AbstractServlet
|
66
|
-
def do_GET(req, res)
|
67
|
-
res['Content-Type'] = "text/html"
|
68
|
-
|
69
|
-
req.query.each do |x,y|
|
70
|
-
res[x] = y
|
71
|
-
end
|
72
|
-
|
73
|
-
body = ''
|
74
|
-
req.each_header do |k,v|
|
75
|
-
body << "#{k}|#{v}\n"
|
76
|
-
end
|
77
|
-
res.body = body
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
class RefererServlet < WEBrick::HTTPServlet::AbstractServlet
|
82
|
-
def do_GET(req, res)
|
83
|
-
res['Content-Type'] = "text/html"
|
84
|
-
res.body = req['Referer'] || ''
|
85
|
-
end
|
86
|
-
|
87
|
-
def do_POST(req, res)
|
88
|
-
res['Content-Type'] = "text/html"
|
89
|
-
res.body = req['Referer'] || ''
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
class ModifiedSinceServlet < WEBrick::HTTPServlet::AbstractServlet
|
94
|
-
def do_GET(req, res)
|
95
|
-
s_time = 'Fri, 04 May 2001 00:00:38 GMT'
|
96
|
-
|
97
|
-
my_time = Time.parse(s_time)
|
98
|
-
|
99
|
-
if req['If-Modified-Since']
|
100
|
-
your_time = Time.parse(req['If-Modified-Since'])
|
101
|
-
if my_time > your_time
|
102
|
-
res.body = 'This page was updated since you requested'
|
103
|
-
else
|
104
|
-
res.status = 304
|
105
|
-
end
|
106
|
-
else
|
107
|
-
res.body = 'You did not send an If-Modified-Since header'
|
108
|
-
end
|
109
|
-
|
110
|
-
res['Last-Modified'] = s_time
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
class GzipServlet < WEBrick::HTTPServlet::AbstractServlet
|
115
|
-
def do_GET(req, res)
|
116
|
-
if req['Accept-Encoding'] =~ /gzip/
|
117
|
-
if req.query['file']
|
118
|
-
File.open("#{BASE_DIR}/htdocs/#{req.query['file']}", 'r') do |file|
|
119
|
-
string = ""
|
120
|
-
zipped = StringIO.new string, 'w'
|
121
|
-
gz = Zlib::GzipWriter.new(zipped)
|
122
|
-
gz.write file.read
|
123
|
-
gz.close
|
124
|
-
res.body = string
|
125
|
-
end
|
126
|
-
else
|
127
|
-
res.body = ''
|
128
|
-
end
|
129
|
-
res['Content-Encoding'] = 'gzip'
|
130
|
-
res['Content-Type'] = "text/html"
|
131
|
-
else
|
132
|
-
res.code = 400
|
133
|
-
res.body = 'no gzip'
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
class BadContentTypeTest < WEBrick::HTTPServlet::AbstractServlet
|
139
|
-
def do_GET(req, res)
|
140
|
-
res['Content-Type'] = "text/xml"
|
141
|
-
res.body = "Hello World"
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
class ContentTypeTest < WEBrick::HTTPServlet::AbstractServlet
|
146
|
-
def do_GET(req, res)
|
147
|
-
ct = req.query['ct'] || "text/html; charset=utf-8"
|
148
|
-
res['Content-Type'] = ct
|
149
|
-
res.body = "Hello World"
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
class FileUploadTest < WEBrick::HTTPServlet::AbstractServlet
|
154
|
-
def do_POST(req, res)
|
155
|
-
res.body = req.body
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
class InfiniteRefreshTest < WEBrick::HTTPServlet::AbstractServlet
|
160
|
-
def do_GET(req, res)
|
161
|
-
res['Content-Type'] = req.query['ct'] || "text/html"
|
162
|
-
res.status = req.query['code'] ? req.query['code'].to_i : '302'
|
163
|
-
number = req.query['q'] ? req.query['q'].to_i : 0
|
164
|
-
res['Refresh'] = " 0;url=http://localhost/infinite_refresh?q=#{number + 1}\r\n";
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
class RefreshWithoutUrl < WEBrick::HTTPServlet::AbstractServlet
|
169
|
-
@@count = 0
|
170
|
-
def do_GET(req, res)
|
171
|
-
res['Content-Type'] = "text/html"
|
172
|
-
@@count += 1
|
173
|
-
if @@count > 1
|
174
|
-
res['Refresh'] = "0; url=http://localhost/index.html";
|
175
|
-
else
|
176
|
-
res['Refresh'] = "0";
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
class RefreshWithEmptyUrl < WEBrick::HTTPServlet::AbstractServlet
|
182
|
-
@@count = 0
|
183
|
-
def do_GET(req, res)
|
184
|
-
res['Content-Type'] = "text/html"
|
185
|
-
@@count += 1
|
186
|
-
if @@count > 1
|
187
|
-
res['Refresh'] = "0; url=http://localhost/index.html";
|
188
|
-
else
|
189
|
-
res['Refresh'] = "0; url=";
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
class InfiniteRedirectTest < WEBrick::HTTPServlet::AbstractServlet
|
195
|
-
def do_GET(req, res)
|
196
|
-
res['Content-Type'] = req.query['ct'] || "text/html"
|
197
|
-
res.status = req.query['code'] ? req.query['code'].to_i : '302'
|
198
|
-
number = req.query['q'] ? req.query['q'].to_i : 0
|
199
|
-
res['Location'] = "/infinite_redirect?q=#{number + 1}"
|
200
|
-
end
|
201
|
-
alias :do_POST :do_GET
|
202
|
-
end
|
203
|
-
|
204
|
-
class RedirectOkTest < WEBrick::HTTPServlet::AbstractServlet
|
205
|
-
def do_GET(req, res)
|
206
|
-
res['Content-Type'] = "text/plain"
|
207
|
-
case q = req.query['q']
|
208
|
-
when '1'..'2'
|
209
|
-
res.status = '301'
|
210
|
-
q.succ!
|
211
|
-
when '3'..'4'
|
212
|
-
res.status = '302'
|
213
|
-
q.succ!
|
214
|
-
when '5'
|
215
|
-
res.status = '200'
|
216
|
-
res.body = 'Finally OK.'
|
217
|
-
return
|
218
|
-
else
|
219
|
-
res.status = '301'
|
220
|
-
q = '1'
|
221
|
-
end
|
222
|
-
res['Location'] = "/redirect_ok?q=#{q}"
|
223
|
-
end
|
224
|
-
alias :do_POST :do_GET
|
225
|
-
end
|
226
|
-
|
227
|
-
class RedirectTest < WEBrick::HTTPServlet::AbstractServlet
|
228
|
-
def do_GET(req, res)
|
229
|
-
res['Content-Type'] = req.query['ct'] || "text/html"
|
230
|
-
res.status = req.query['code'] ? req.query['code'].to_i : '302'
|
231
|
-
res['Location'] = "/verb"
|
232
|
-
end
|
233
|
-
|
234
|
-
alias :do_POST :do_GET
|
235
|
-
alias :do_HEAD :do_GET
|
236
|
-
alias :do_PUT :do_GET
|
237
|
-
alias :do_DELETE :do_GET
|
238
|
-
end
|
239
|
-
|
240
|
-
class ResponseCodeTest < WEBrick::HTTPServlet::AbstractServlet
|
241
|
-
def do_GET(req, res)
|
242
|
-
res['Content-Type'] = req.query['ct'] || "text/html"
|
243
|
-
if req.query['code']
|
244
|
-
code = req.query['code'].to_i
|
245
|
-
case code
|
246
|
-
when 300, 301, 302, 303, 304, 305, 307
|
247
|
-
res['Location'] = "/index.html"
|
248
|
-
end
|
249
|
-
res.status = code
|
250
|
-
else
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
class HttpRefreshTest < WEBrick::HTTPServlet::AbstractServlet
|
256
|
-
def do_GET(req, res)
|
257
|
-
res['Content-Type'] = req.query['ct'] || "text/html"
|
258
|
-
refresh_time = req.query['refresh_time'] || 0
|
259
|
-
refresh_url = req.query['refresh_url'] || '/index.html'
|
260
|
-
res['Refresh'] = " #{refresh_time};url=#{refresh_url}\r\n";
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
class FormTest < WEBrick::HTTPServlet::AbstractServlet
|
265
|
-
def do_GET(req, res)
|
266
|
-
res.body = "<HTML><body>"
|
267
|
-
req.query.each_key { |k|
|
268
|
-
req.query[k].each_data { |data|
|
269
|
-
res.body << "<a href=\"#\">#{WEBrick::HTTPUtils.unescape(k)}:#{WEBrick::HTTPUtils.unescape(data)}</a><br />"
|
270
|
-
}
|
271
|
-
}
|
272
|
-
res.body << "<div id=\"query\">#{res.query}</div></body></HTML>"
|
273
|
-
res['Content-Type'] = "text/html"
|
274
|
-
end
|
275
|
-
|
276
|
-
def do_POST(req, res)
|
277
|
-
res.body = "<HTML><body>"
|
278
|
-
|
279
|
-
req.query.each_key { |k|
|
280
|
-
req.query[k].each_data { |data|
|
281
|
-
res.body << "<a href=\"#\">#{k}:#{data}</a><br />"
|
282
|
-
}
|
283
|
-
}
|
284
|
-
|
285
|
-
res.body << "<div id=\"query\">#{req.body}</div></body></HTML>"
|
286
|
-
res['Content-Type'] = "text/html"
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
class OneCookieTest < WEBrick::HTTPServlet::AbstractServlet
|
291
|
-
def do_GET(req, res)
|
292
|
-
cookie = WEBrick::Cookie.new("foo", "bar")
|
293
|
-
cookie.path = "/"
|
294
|
-
cookie.expires = Time.now + 86400
|
295
|
-
res.cookies << cookie
|
296
|
-
res['Content-Type'] = "text/html"
|
297
|
-
res.body = "<html><body>hello</body></html>"
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
class OneCookieNoSpacesTest < WEBrick::HTTPServlet::AbstractServlet
|
302
|
-
def do_GET(req, res)
|
303
|
-
cookie = WEBrick::Cookie.new("foo", "bar")
|
304
|
-
cookie.path = "/"
|
305
|
-
cookie.expires = Time.now + 86400
|
306
|
-
res.cookies << cookie.to_s.gsub(/; /, ';')
|
307
|
-
res['Content-Type'] = "text/html"
|
308
|
-
res.body = "<html><body>hello</body></html>"
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
class ManyCookiesTest < WEBrick::HTTPServlet::AbstractServlet
|
313
|
-
def do_GET(req, res)
|
314
|
-
name_cookie = WEBrick::Cookie.new("name", "Aaron")
|
315
|
-
name_cookie.path = "/"
|
316
|
-
name_cookie.expires = Time.now + 86400
|
317
|
-
res.cookies << name_cookie
|
318
|
-
res.cookies << name_cookie
|
319
|
-
res.cookies << name_cookie
|
320
|
-
res.cookies << name_cookie
|
321
|
-
|
322
|
-
expired_cookie = WEBrick::Cookie.new("expired", "doh")
|
323
|
-
expired_cookie.path = "/"
|
324
|
-
expired_cookie.expires = Time.now - 86400
|
325
|
-
res.cookies << expired_cookie
|
326
|
-
|
327
|
-
different_path_cookie = WEBrick::Cookie.new("a_path", "some_path")
|
328
|
-
different_path_cookie.path = "/some_path"
|
329
|
-
different_path_cookie.expires = Time.now + 86400
|
330
|
-
res.cookies << different_path_cookie
|
331
|
-
|
332
|
-
no_path_cookie = WEBrick::Cookie.new("no_path", "no_path")
|
333
|
-
no_path_cookie.expires = Time.now + 86400
|
334
|
-
res.cookies << no_path_cookie
|
335
|
-
|
336
|
-
no_exp_path_cookie = WEBrick::Cookie.new("no_expires", "nope")
|
337
|
-
no_exp_path_cookie.path = "/"
|
338
|
-
res.cookies << no_exp_path_cookie
|
339
|
-
|
340
|
-
res['Content-Type'] = "text/html"
|
341
|
-
res.body = "<html><body>hello</body></html>"
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
|
-
class ManyCookiesAsStringTest < WEBrick::HTTPServlet::AbstractServlet
|
346
|
-
def do_GET(req, res)
|
347
|
-
cookies = []
|
348
|
-
name_cookie = WEBrick::Cookie.new("name", "Aaron")
|
349
|
-
name_cookie.path = "/"
|
350
|
-
name_cookie.expires = Time.now + 86400
|
351
|
-
name_cookie.domain = 'localhost'
|
352
|
-
cookies << name_cookie
|
353
|
-
cookies << name_cookie
|
354
|
-
cookies << name_cookie
|
355
|
-
cookies << "#{name_cookie}; HttpOnly"
|
356
|
-
|
357
|
-
expired_cookie = WEBrick::Cookie.new("expired", "doh")
|
358
|
-
expired_cookie.path = "/"
|
359
|
-
expired_cookie.expires = Time.now - 86400
|
360
|
-
cookies << expired_cookie
|
361
|
-
|
362
|
-
different_path_cookie = WEBrick::Cookie.new("a_path", "some_path")
|
363
|
-
different_path_cookie.path = "/some_path"
|
364
|
-
different_path_cookie.expires = Time.now + 86400
|
365
|
-
cookies << different_path_cookie
|
366
|
-
|
367
|
-
no_path_cookie = WEBrick::Cookie.new("no_path", "no_path")
|
368
|
-
no_path_cookie.expires = Time.now + 86400
|
369
|
-
cookies << no_path_cookie
|
370
|
-
|
371
|
-
no_exp_path_cookie = WEBrick::Cookie.new("no_expires", "nope")
|
372
|
-
no_exp_path_cookie.path = "/"
|
373
|
-
cookies << no_exp_path_cookie
|
374
|
-
|
375
|
-
res['Set-Cookie'] = cookies.join(', ')
|
376
|
-
|
377
|
-
res['Content-Type'] = "text/html"
|
378
|
-
res.body = "<html><body>hello</body></html>"
|
379
|
-
end
|
380
|
-
end
|
381
|
-
|
382
|
-
class SendCookiesTest < WEBrick::HTTPServlet::AbstractServlet
|
383
|
-
def do_GET(req, res)
|
384
|
-
res['Content-Type'] = "text/html"
|
385
|
-
res.body = "<html><body>"
|
386
|
-
req.cookies.each { |c|
|
387
|
-
res.body << "<a href=\"#\">#{c.name}:#{c.value}</a>"
|
388
|
-
}
|
389
|
-
res.body << "</body></html>"
|
390
|
-
end
|
391
|
-
end
|
392
|
-
|
393
|
-
class QuotedValueCookieTest < WEBrick::HTTPServlet::AbstractServlet
|
394
|
-
def do_GET(req, res)
|
395
|
-
cookie = WEBrick::Cookie.new("quoted", "\"value\"")
|
396
|
-
cookie.path = "/"
|
397
|
-
cookie.expires = Time.now + 86400
|
398
|
-
res.cookies << cookie
|
399
|
-
res['Content-Type'] = "text/html"
|
400
|
-
res.body = "<html><body>hello</body></html>"
|
401
|
-
end
|
402
|
-
end
|
data/test/ssl_server.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'webrick'
|
2
|
-
require 'webrick/https'
|
3
|
-
require 'servlets'
|
4
|
-
require 'logger'
|
5
|
-
|
6
|
-
base_dir = FileTest.exists?(Dir::pwd + '/test') ? Dir::pwd + '/test' : Dir::pwd
|
7
|
-
|
8
|
-
s = WEBrick::HTTPServer.new(
|
9
|
-
:Port => 2002,
|
10
|
-
:DocumentRoot => base_dir + "/htdocs",
|
11
|
-
:SSLEnable => true,
|
12
|
-
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
|
13
|
-
:SSLCertificate => OpenSSL::X509::Certificate.new(
|
14
|
-
File.read("data/server.crt")
|
15
|
-
),
|
16
|
-
:SSLPrivateKey => OpenSSL::PKey::RSA.new(
|
17
|
-
File.read("data/server.pem")
|
18
|
-
),
|
19
|
-
:Logger => Logger.new(nil),
|
20
|
-
:AccessLog => Logger.new(nil)
|
21
|
-
)
|
22
|
-
s.mount("/one_cookie", OneCookieTest)
|
23
|
-
s.mount("/one_cookie_no_space", OneCookieNoSpacesTest)
|
24
|
-
s.mount("/many_cookies", ManyCookiesTest)
|
25
|
-
s.mount("/many_cookies_as_string", ManyCookiesAsStringTest)
|
26
|
-
s.mount("/send_cookies", SendCookiesTest)
|
27
|
-
s.mount("/form_post", FormTest)
|
28
|
-
s.mount("/form post", FormTest)
|
29
|
-
s.mount("/response_code", ResponseCodeTest)
|
30
|
-
s.mount("/file_upload", FileUploadTest)
|
31
|
-
s.mount("/bad_content_type", BadContentTypeTest)
|
32
|
-
s.mount("/content_type_test", ContentTypeTest)
|
33
|
-
|
34
|
-
htpasswd = WEBrick::HTTPAuth::Htpasswd.new(base_dir + '/data/htpasswd')
|
35
|
-
auth = WEBrick::HTTPAuth::BasicAuth.new(
|
36
|
-
:UserDB => htpasswd,
|
37
|
-
:Realm => 'mechanize',
|
38
|
-
:Logger => Logger.new(nil),
|
39
|
-
:AccessLog => Logger.new(nil)
|
40
|
-
)
|
41
|
-
s.mount_proc('/htpasswd_auth') { |req, res|
|
42
|
-
auth.authenticate(req, res)
|
43
|
-
res.body = "You are authenticated"
|
44
|
-
}
|
45
|
-
|
46
|
-
trap("INT") { s.stop }
|
47
|
-
|
48
|
-
s.start
|