aai10-mechanize 2.0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. data/.autotest +6 -0
  2. data/.gitignore +9 -0
  3. data/CHANGELOG.rdoc +652 -0
  4. data/EXAMPLES.rdoc +187 -0
  5. data/FAQ.rdoc +11 -0
  6. data/GUIDE.rdoc +163 -0
  7. data/LICENSE.rdoc +20 -0
  8. data/Manifest.txt +172 -0
  9. data/README.rdoc +63 -0
  10. data/Rakefile +36 -0
  11. data/aai10-mechanize.gemspec +20 -0
  12. data/examples/flickr_upload.rb +22 -0
  13. data/examples/mech-dump.rb +5 -0
  14. data/examples/proxy_req.rb +7 -0
  15. data/examples/rubyforge.rb +20 -0
  16. data/examples/spider.rb +21 -0
  17. data/lib/mechanize.rb +664 -0
  18. data/lib/mechanize/content_type_error.rb +14 -0
  19. data/lib/mechanize/cookie.rb +116 -0
  20. data/lib/mechanize/cookie_jar.rb +202 -0
  21. data/lib/mechanize/element_matcher.rb +35 -0
  22. data/lib/mechanize/file.rb +80 -0
  23. data/lib/mechanize/file_connection.rb +17 -0
  24. data/lib/mechanize/file_request.rb +26 -0
  25. data/lib/mechanize/file_response.rb +74 -0
  26. data/lib/mechanize/file_saver.rb +37 -0
  27. data/lib/mechanize/form.rb +478 -0
  28. data/lib/mechanize/form/button.rb +9 -0
  29. data/lib/mechanize/form/check_box.rb +11 -0
  30. data/lib/mechanize/form/field.rb +44 -0
  31. data/lib/mechanize/form/file_upload.rb +23 -0
  32. data/lib/mechanize/form/image_button.rb +20 -0
  33. data/lib/mechanize/form/multi_select_list.rb +83 -0
  34. data/lib/mechanize/form/option.rb +49 -0
  35. data/lib/mechanize/form/radio_button.rb +48 -0
  36. data/lib/mechanize/form/select_list.rb +40 -0
  37. data/lib/mechanize/headers.rb +25 -0
  38. data/lib/mechanize/history.rb +83 -0
  39. data/lib/mechanize/http.rb +3 -0
  40. data/lib/mechanize/http/agent.rb +738 -0
  41. data/lib/mechanize/inspect.rb +88 -0
  42. data/lib/mechanize/monkey_patch.rb +37 -0
  43. data/lib/mechanize/page.rb +408 -0
  44. data/lib/mechanize/page/base.rb +8 -0
  45. data/lib/mechanize/page/frame.rb +27 -0
  46. data/lib/mechanize/page/image.rb +30 -0
  47. data/lib/mechanize/page/label.rb +20 -0
  48. data/lib/mechanize/page/link.rb +82 -0
  49. data/lib/mechanize/page/meta_refresh.rb +56 -0
  50. data/lib/mechanize/pluggable_parsers.rb +101 -0
  51. data/lib/mechanize/redirect_limit_reached_error.rb +16 -0
  52. data/lib/mechanize/redirect_not_get_or_head_error.rb +19 -0
  53. data/lib/mechanize/response_code_error.rb +22 -0
  54. data/lib/mechanize/response_read_error.rb +27 -0
  55. data/lib/mechanize/robots_disallowed_error.rb +29 -0
  56. data/lib/mechanize/unsupported_scheme_error.rb +8 -0
  57. data/lib/mechanize/util.rb +113 -0
  58. data/test/data/htpasswd +1 -0
  59. data/test/data/server.crt +16 -0
  60. data/test/data/server.csr +12 -0
  61. data/test/data/server.key +15 -0
  62. data/test/data/server.pem +15 -0
  63. data/test/helper.rb +175 -0
  64. data/test/htdocs/alt_text.html +10 -0
  65. data/test/htdocs/bad_form_test.html +9 -0
  66. data/test/htdocs/button.jpg +0 -0
  67. data/test/htdocs/canonical_uri.html +9 -0
  68. data/test/htdocs/dir with spaces/foo.html +1 -0
  69. data/test/htdocs/empty_form.html +6 -0
  70. data/test/htdocs/file_upload.html +26 -0
  71. data/test/htdocs/find_link.html +41 -0
  72. data/test/htdocs/form_multi_select.html +16 -0
  73. data/test/htdocs/form_multival.html +37 -0
  74. data/test/htdocs/form_no_action.html +18 -0
  75. data/test/htdocs/form_no_input_name.html +16 -0
  76. data/test/htdocs/form_select.html +16 -0
  77. data/test/htdocs/form_select_all.html +16 -0
  78. data/test/htdocs/form_select_none.html +17 -0
  79. data/test/htdocs/form_select_noopts.html +10 -0
  80. data/test/htdocs/form_set_fields.html +14 -0
  81. data/test/htdocs/form_test.html +188 -0
  82. data/test/htdocs/frame_referer_test.html +10 -0
  83. data/test/htdocs/frame_test.html +30 -0
  84. data/test/htdocs/google.html +13 -0
  85. data/test/htdocs/iframe_test.html +16 -0
  86. data/test/htdocs/index.html +6 -0
  87. data/test/htdocs/link with space.html +5 -0
  88. data/test/htdocs/meta_cookie.html +11 -0
  89. data/test/htdocs/no_title_test.html +6 -0
  90. data/test/htdocs/nofollow.html +9 -0
  91. data/test/htdocs/noindex.html +9 -0
  92. data/test/htdocs/norobots.html +8 -0
  93. data/test/htdocs/rails_3_encoding_hack_form_test.html +27 -0
  94. data/test/htdocs/rel_nofollow.html +8 -0
  95. data/test/htdocs/relative/tc_relative_links.html +21 -0
  96. data/test/htdocs/robots.html +8 -0
  97. data/test/htdocs/robots.txt +2 -0
  98. data/test/htdocs/tc_bad_charset.html +9 -0
  99. data/test/htdocs/tc_bad_links.html +5 -0
  100. data/test/htdocs/tc_base_images.html +10 -0
  101. data/test/htdocs/tc_base_link.html +8 -0
  102. data/test/htdocs/tc_blank_form.html +11 -0
  103. data/test/htdocs/tc_charset.html +6 -0
  104. data/test/htdocs/tc_checkboxes.html +19 -0
  105. data/test/htdocs/tc_encoded_links.html +5 -0
  106. data/test/htdocs/tc_field_precedence.html +11 -0
  107. data/test/htdocs/tc_follow_meta.html +8 -0
  108. data/test/htdocs/tc_form_action.html +48 -0
  109. data/test/htdocs/tc_images.html +8 -0
  110. data/test/htdocs/tc_links.html +18 -0
  111. data/test/htdocs/tc_meta_in_body.html +9 -0
  112. data/test/htdocs/tc_no_attributes.html +16 -0
  113. data/test/htdocs/tc_pretty_print.html +17 -0
  114. data/test/htdocs/tc_radiobuttons.html +17 -0
  115. data/test/htdocs/tc_referer.html +16 -0
  116. data/test/htdocs/tc_relative_links.html +19 -0
  117. data/test/htdocs/tc_textarea.html +23 -0
  118. data/test/htdocs/test_bad_encoding.html +52 -0
  119. data/test/htdocs/test_click.html +11 -0
  120. data/test/htdocs/unusual______.html +5 -0
  121. data/test/servlets.rb +402 -0
  122. data/test/ssl_server.rb +48 -0
  123. data/test/test_cookies.rb +129 -0
  124. data/test/test_form_action.rb +52 -0
  125. data/test/test_form_as_hash.rb +59 -0
  126. data/test/test_form_button.rb +46 -0
  127. data/test/test_frames.rb +34 -0
  128. data/test/test_headers.rb +33 -0
  129. data/test/test_history.rb +118 -0
  130. data/test/test_history_added.rb +16 -0
  131. data/test/test_html_unscape_forms.rb +46 -0
  132. data/test/test_if_modified_since.rb +20 -0
  133. data/test/test_images.rb +19 -0
  134. data/test/test_mechanize.rb +852 -0
  135. data/test/test_mechanize_cookie.rb +345 -0
  136. data/test/test_mechanize_cookie_jar.rb +433 -0
  137. data/test/test_mechanize_file.rb +53 -0
  138. data/test/test_mechanize_file_request.rb +19 -0
  139. data/test/test_mechanize_file_response.rb +21 -0
  140. data/test/test_mechanize_form.rb +576 -0
  141. data/test/test_mechanize_form_check_box.rb +37 -0
  142. data/test/test_mechanize_form_encoding.rb +120 -0
  143. data/test/test_mechanize_form_field.rb +21 -0
  144. data/test/test_mechanize_form_image_button.rb +12 -0
  145. data/test/test_mechanize_form_textarea.rb +51 -0
  146. data/test/test_mechanize_http_agent.rb +697 -0
  147. data/test/test_mechanize_link.rb +84 -0
  148. data/test/test_mechanize_page_encoding.rb +147 -0
  149. data/test/test_mechanize_page_link.rb +382 -0
  150. data/test/test_mechanize_page_meta_refresh.rb +115 -0
  151. data/test/test_mechanize_redirect_not_get_or_head_error.rb +18 -0
  152. data/test/test_mechanize_subclass.rb +22 -0
  153. data/test/test_mechanize_util.rb +92 -0
  154. data/test/test_multi_select.rb +118 -0
  155. data/test/test_no_attributes.rb +13 -0
  156. data/test/test_option.rb +18 -0
  157. data/test/test_pluggable_parser.rb +136 -0
  158. data/test/test_post_form.rb +37 -0
  159. data/test/test_pretty_print.rb +22 -0
  160. data/test/test_radiobutton.rb +75 -0
  161. data/test/test_redirect_limit_reached.rb +39 -0
  162. data/test/test_redirect_ok.rb +25 -0
  163. data/test/test_referer.rb +81 -0
  164. data/test/test_relative_links.rb +40 -0
  165. data/test/test_request.rb +13 -0
  166. data/test/test_response_code.rb +53 -0
  167. data/test/test_robots.rb +72 -0
  168. data/test/test_save_file.rb +48 -0
  169. data/test/test_scheme.rb +48 -0
  170. data/test/test_select.rb +119 -0
  171. data/test/test_select_all.rb +15 -0
  172. data/test/test_select_none.rb +15 -0
  173. data/test/test_select_noopts.rb +18 -0
  174. data/test/test_set_fields.rb +44 -0
  175. data/test/test_ssl_server.rb +20 -0
  176. metadata +360 -0
@@ -0,0 +1,52 @@
1
+ <html>
2
+ <head>
3
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8; charset=utf-8"/>
4
+ <title>Page Title</title>
5
+ </head>
6
+ <body>
7
+ <h1>Post Form 1</h1>
8
+ <form name="post_form1" method="post" action="/form_post?a=b&amp;b=c">
9
+ <table>
10
+ <tr>
11
+ <td>First Name</td>
12
+ <td><input type="text" name="first_name" /></td>
13
+ </tr>
14
+ </table><br />
15
+ <input type="submit" value="Submit" />
16
+ </form>
17
+
18
+ <h1>Post Form 2</h1>
19
+ <form name="post_form2" method="get" action="/form_post?a=b&amp;b=c">
20
+ <table>
21
+ <tr>
22
+ <td>First Name</td>
23
+ <td><input type="text" name="first_name" /></td>
24
+ </tr>
25
+ </table><br />
26
+ <input type="submit" value="Submit" />
27
+ </form>
28
+
29
+ <h1>Post Form 3</h1>
30
+ <form name="post_form3" method="post" action="/form_post?a=b&b=c">
31
+ <table>
32
+ <tr>
33
+ <td>First Name</td>
34
+ <td><input type="text" name="first_name" /></td>
35
+ </tr>
36
+ </table><br />
37
+ <input type="submit" value="Submit" />
38
+ </form>
39
+
40
+ <h1>Post Form 4</h1>
41
+ <form name="post_form4" method="post" action="/form_post#1">
42
+ <table>
43
+ <tr>
44
+ <td>First Name</td>
45
+ <td><input type="text" name="first_name" /></td>
46
+ </tr>
47
+ </table><br />
48
+ <input type="submit" value="Submit" />
49
+ </form>
50
+ </body>
51
+ </html>
52
+
@@ -0,0 +1,11 @@
1
+ <html>
2
+ <head><title>Page Title</title></head>
3
+ <body>
4
+ <a href="/frame_test.html">This link is not called "A Link"</a>
5
+ <form method="get" action="/frame_test.html">
6
+ <input type="text" name="words" value="nil">
7
+ <input type="submit" value="A Button">
8
+ </form>
9
+ <a href="/index.html">A Link</a>
10
+ </body>
11
+ </html>
@@ -0,0 +1,5 @@
1
+ <html>
2
+ <body>
3
+ This is a webpage that has a very unusual name.
4
+ </body>
5
+ </html>
@@ -0,0 +1,402 @@
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