Class: WEBrick::Cookie
- Inherits:
-
Object
- Object
- WEBrick::Cookie
- Defined in:
- lib/webrick/cookie.rb
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#max_age ⇒ Object
Returns the value of attribute max_age.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#secure ⇒ Object
Returns the value of attribute secure.
-
#value ⇒ Object
Returns the value of attribute value.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
-
.parse(str) ⇒ Object
Cookie::parse() It parses Cookie field sent from the user agent.
- .parse_set_cookie(str) ⇒ Object
- .parse_set_cookies(str) ⇒ Object
Instance Method Summary collapse
- #expires ⇒ Object
- #expires=(t) ⇒ Object
-
#initialize(name, value) ⇒ Cookie
constructor
attr_accessor :comment_url, :discard, :port.
- #to_s ⇒ Object
Constructor Details
#initialize(name, value) ⇒ Cookie
attr_accessor :comment_url, :discard, :port
23 24 25 26 27 28 29 30 |
# File 'lib/webrick/cookie.rb', line 23 def initialize(name, value) @name = name @value = value @version = 0 # Netscape Cookie @domain = @path = @secure = @comment = @max_age = @expires = @comment_url = @discard = @port = nil end |
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment.
20 21 22 |
# File 'lib/webrick/cookie.rb', line 20 def comment @comment end |
#domain ⇒ Object
Returns the value of attribute domain.
19 20 21 |
# File 'lib/webrick/cookie.rb', line 19 def domain @domain end |
#max_age ⇒ Object
Returns the value of attribute max_age.
20 21 22 |
# File 'lib/webrick/cookie.rb', line 20 def max_age @max_age end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/webrick/cookie.rb', line 17 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
19 20 21 |
# File 'lib/webrick/cookie.rb', line 19 def path @path end |
#secure ⇒ Object
Returns the value of attribute secure.
19 20 21 |
# File 'lib/webrick/cookie.rb', line 19 def secure @secure end |
#value ⇒ Object
Returns the value of attribute value.
18 19 20 |
# File 'lib/webrick/cookie.rb', line 18 def value @value end |
#version ⇒ Object
Returns the value of attribute version.
18 19 20 |
# File 'lib/webrick/cookie.rb', line 18 def version @version end |
Class Method Details
.parse(str) ⇒ Object
Cookie::parse()
It parses Cookie field sent from the user agent.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/webrick/cookie.rb', line 55 def self.parse(str) if str ret = [] = nil ver = 0 str.split(/[;,]\s+/).each{|x| key, val = x.split(/=/,2) val = val ? HTTPUtils::dequote(val) : "" case key when "$Version"; ver = val.to_i when "$Path"; .path = val when "$Domain"; .domain = val when "$Port"; .port = val else ret << if = self.new(key, val) .version = ver end } ret << if ret end end |
.parse_set_cookie(str) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/webrick/cookie.rb', line 79 def self.(str) = str.split(/;/) first_elem = .shift first_elem.strip! key, value = first_elem.split(/=/, 2) = new(key, HTTPUtils.dequote(value)) .each{|pair| pair.strip! key, value = pair.split(/=/, 2) if value value = HTTPUtils.dequote(value.strip) end case key.downcase when "domain" then .domain = value when "path" then .path = value when "expires" then .expires = value when "max-age" then .max_age = Integer(value) when "comment" then .comment = value when "version" then .version = Integer(value) when "secure" then .secure = true end } return end |
.parse_set_cookies(str) ⇒ Object
104 105 106 107 108 |
# File 'lib/webrick/cookie.rb', line 104 def self.(str) return str.split(/,(?=[^;,]*=)|,$/).collect{|c| (c) } end |
Instance Method Details
#expires ⇒ Object
36 37 38 |
# File 'lib/webrick/cookie.rb', line 36 def expires @expires && Time.parse(@expires) end |
#expires=(t) ⇒ Object
32 33 34 |
# File 'lib/webrick/cookie.rb', line 32 def expires=(t) @expires = t && (t.is_a?(Time) ? t.httpdate : t.to_s) end |
#to_s ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/webrick/cookie.rb', line 40 def to_s ret = "" ret << @name << "=" << @value ret << "; " << "Version=" << @version.to_s if @version > 0 ret << "; " << "Domain=" << @domain if @domain ret << "; " << "Expires=" << @expires if @expires ret << "; " << "Max-Age=" << @max_age.to_s if @max_age ret << "; " << "Comment=" << @comment if @comment ret << "; " << "Path=" << @path if @path ret << "; " << "Secure" if @secure ret end |