Class WWW::Mechanize::Cookie
In: lib/www/mechanize/cookie.rb
Parent: WEBrick::Cookie
Mechanize\n[lib/www/mechanize.rb\nlib/www/mechanize/content_type_error.rb\nlib/www/mechanize/cookie.rb\nlib/www/mechanize/cookie_jar.rb\nlib/www/mechanize/file.rb\nlib/www/mechanize/file_saver.rb\nlib/www/mechanize/form.rb\nlib/www/mechanize/form/button.rb\nlib/www/mechanize/form/check_box.rb\nlib/www/mechanize/form/field.rb\nlib/www/mechanize/form/file_upload.rb\nlib/www/mechanize/form/image_button.rb\nlib/www/mechanize/form/multi_select_list.rb\nlib/www/mechanize/form/option.rb\nlib/www/mechanize/form/radio_button.rb\nlib/www/mechanize/form/select_list.rb\nlib/www/mechanize/headers.rb\nlib/www/mechanize/history.rb\nlib/www/mechanize/list.rb\nlib/www/mechanize/monkey_patch.rb\nlib/www/mechanize/page.rb\nlib/www/mechanize/page/base.rb\nlib/www/mechanize/page/frame.rb\nlib/www/mechanize/page/link.rb\nlib/www/mechanize/page/meta.rb\nlib/www/mechanize/pluggable_parsers.rb\nlib/www/mechanize/response_code_error.rb\nlib/www/mechanize/unsupported_scheme_error.rb] lib/www/mechanize/headers.rb WWW dot/m_32_0.png

This class is used to represent an HTTP Cookie.

Methods

parse   to_s  

Public Class methods

[Source]

    # File lib/www/mechanize/cookie.rb, line 8
 8:       def self.parse(uri, str, log = nil)
 9:         return str.split(/,(?=[^;,]*=)|,$/).collect { |c|
10:           cookie_elem = c.split(/;/)
11:           first_elem = cookie_elem.shift
12:           first_elem.strip!
13:           key, value = first_elem.split(/=/, 2)
14:           cookie = new(key, WEBrick::HTTPUtils.dequote(value))
15:           cookie_elem.each{|pair|
16:             pair.strip!
17:             key, value = pair.split(/=/, 2)
18:             if value
19:               value = WEBrick::HTTPUtils.dequote(value.strip)
20:             end
21:             case key.downcase
22:             when "domain"  then cookie.domain  = value.sub(/^\./, '')
23:             when "path"    then cookie.path    = value
24:             when 'expires'
25:               begin
26:                 cookie.expires = Time::parse(value)
27:               rescue
28:                 if log
29:                   log.warn("Couldn't parse expires: #{value}")
30:                 end
31:               end
32:             when "max-age" then
33:               begin
34:                 cookie.max_age = Integer(value)
35:               rescue
36:                 log.warn("Couldn't parse max age '#{value}'") if log
37:                 cookie.max_age = nil
38:               end
39:             when "comment" then cookie.comment = value
40:             when "version" then
41:               begin
42:                 cookie.version = Integer(value)
43:               rescue
44:                 log.warn("Couldn't parse version '#{value}'") if log
45:                 cookie.version = nil
46:               end
47:             when "secure"  then cookie.secure = true
48:             end
49:           }
50: 
51:           cookie.path    ||= uri.path.to_s.sub(/[^\/]*$/, '')
52:           cookie.secure  ||= false
53:           cookie.domain  ||= uri.host
54:           # Move this in to the cookie jar
55:           yield cookie if block_given?
56:         }
57:       end

Public Instance methods

[Source]

    # File lib/www/mechanize/cookie.rb, line 59
59:       def to_s
60:         "#{@name}=#{@value}"
61:       end

[Validate]