Extended maintenance of Ruby versions 1.8.7 and 1.9.2 will end on July 31, 2014. Read more

In Files

  • webrick/cookie.rb
  • webrick/httprequest.rb

WEBrick::Cookie

Attributes

comment[RW]
domain[RW]
max_age[RW]
name[R]
path[RW]
secure[RW]
value[RW]
version[RW]

Public Class Methods

new(name, value) click to toggle source

attr_accessor :comment_url, :discard, :port

 
               # File 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
            
parse(str) click to toggle source

::parse

It parses Cookie field sent from the user agent.
 
               # File webrick/cookie.rb, line 55
def self.parse(str)
  if str
    ret = []
    cookie = 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";    cookie.path = val
      when "$Domain";  cookie.domain = val
      when "$Port";    cookie.port = val
      else
        ret << cookie if cookie
        cookie = self.new(key, val)
        cookie.version = ver
      end
    }
    ret << cookie if cookie
    ret
  end
end
            
parse_set_cookies(str) click to toggle source
 
               # File webrick/cookie.rb, line 104
def self.parse_set_cookies(str)
  return str.split(/,(?=[^;,]*=)|,$/).collect{|c|
    parse_set_cookie(c)
  }
end
            

Public Instance Methods

expires() click to toggle source
 
               # File webrick/cookie.rb, line 36
def expires
  @expires && Time.parse(@expires)
end
            
expires=(t) click to toggle source
 
               # File webrick/cookie.rb, line 32
def expires=(t)
  @expires = t && (t.is_a?(Time) ? t.httpdate : t.to_s)
end
            
to_s() click to toggle source
 
               # File 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
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus