Class: ManyCookiesServlet

Inherits:
WEBrick::HTTPServlet::AbstractServlet
  • Object
show all
Defined in:
lib/mechanize/test_case.rb

Instance Method Summary collapse

Instance Method Details

#do_GET(req, res) ⇒ Object



322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/mechanize/test_case.rb', line 322

def do_GET(req, res)
  name_cookie = WEBrick::Cookie.new("name", "Aaron")
  name_cookie.path = "/"
  name_cookie.expires = Time.now + 86400
  res.cookies << name_cookie
  res.cookies << name_cookie
  res.cookies << name_cookie
  res.cookies << name_cookie

  expired_cookie = WEBrick::Cookie.new("expired", "doh")
  expired_cookie.path = "/"
  expired_cookie.expires = Time.now - 86400
  res.cookies << expired_cookie

  different_path_cookie = WEBrick::Cookie.new("a_path", "some_path")
  different_path_cookie.path = "/some_path"
  different_path_cookie.expires = Time.now + 86400
  res.cookies << different_path_cookie

  no_path_cookie = WEBrick::Cookie.new("no_path", "no_path")
  no_path_cookie.expires = Time.now + 86400
  res.cookies << no_path_cookie

  no_exp_path_cookie = WEBrick::Cookie.new("no_expires", "nope")
  no_exp_path_cookie.path = "/"
  res.cookies << no_exp_path_cookie

  res['Content-Type'] = "text/html"
  res.body = "<html><body>hello</body></html>"
end