Subversion Info

Rev
406
Last Checked In
2007-07-18 17:01:59 (9 months ago)
Checked in by
bbleything

Parent

Class Index

Quicksearch

Arrow::Cookie

A class for parsing and generating HTTP cookies

Constants

SVNRev
SVN Revision
SVNId
SVN Id
CookieDateFormat
(Not documented)
CookieVersion
  RFC 2109: HTTP State Management Mechanism
When it sends a request to an origin server, the user agent sends a Cookie request header to the origin server if it has cookies that are applicable to the request, based on
  * the request-host;
  * the request-URI;
  * the cookie's age.

The syntax for the header is:

cookie = "Cookie:" cookie-version

                           1*((";" | ",") cookie-value)

cookie-value = NAME "=" VALUE [";" path] [";" domain] cookie-version = "$Version" "=" value NAME = attr VALUE = value path = "$Path" "=" value domain = "$Domain" "=" value

CookiePath
(Not documented)
CookieDomain
(Not documented)
CTLs
  RFC2068: Hypertext Transfer Protocol -- HTTP/1.1
CTL = <any US-ASCII control character
                 (octets 0 - 31) and DEL (127)>

token = 1*<any CHAR except CTLs or tspecials>

tspecials = "(" | ")" | "<" | ">" | "@"

               | "," | ";" | ":" | "\" | <">
               | "/" | "[" | "]" | "?" | "="
               | "{" | "}" | SP | HT
TSpecials
(Not documented)
NonTokenChar
(Not documented)
HTTPToken
(Not documented)
Seconds
Number of seconds in the various offset types

Attributes

comment[RW]
Because cookies can contain private information about a user, the Cookie attribute allows an origin server to document its intended use of a cookie. The user can inspect the information to decide whether to initiate or continue a session with this cookie.
domain[R]
The domain the cookie belongs to
expires[R]
The cookie‘s expiration (a Time object)
max_age[R]
The lifetime of the cookie, in seconds.
name[RW]
The name of the cookie
path[RW]
The path the cookie applies to
secure[W]
The cookie‘s ‘secure’ flag.
values[RW]
The Array of cookie values
version[RW]
The cookie version. 0 (the default) is fine for most uses

Public Class Methods

dequote( string ) click to toggle source

Strip surrounding double quotes from a copy of the specified string and return it.

    # File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 48
48:     def self::dequote( string )
49:         /^"((?:[^"]+|\\.)*)"/.match( string ) ? $1 : string.dup
50:     end
new( name, values, options={} ) click to toggle source

Create a new Arrow::Cookie object with the specified name and values.

     # File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 157
157:     def initialize( name, values, options={} )
158:         values = [ values ] unless values.is_a?( Array )
159:         @name = name
160:         @values = values
161: 
162:         @domain = nil
163:         @path = nil
164:         @secure = false
165:         @comment = nil
166:         @max_age = nil
167:         @expires = nil
168:         @version = 0
169:         
170:         options.each do |meth, val|
171:             self.__send__( "#{meth}=", val )
172:         end
173:     end
parse( header ) click to toggle source

Parse the specified ‘Cookie:’ header value and return a Hash of one or more new Arrow::Cookie objects, keyed by name.

     # File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 102
102:     def self::parse( header )
103:         return {} if header.nil? or header.empty?
104:         Arrow::Logger[self].debug "Parsing cookie header: %p" % [ header ]
105:         cookies = []
106:         version = 0
107:         header = header.strip
108: 
109:         # "$Version" = value
110:         if CookieVersion.match( header )
111:             Arrow::Logger[self].debug "  Found cookie version %p" % [ $1 ]
112:             version = Integer( dequote($1) )
113:             header.slice!( CookieVersion )
114:         end
115: 
116:         # 1*((";" | ",") NAME "=" VALUE [";" path] [";" domain])
117:         header.split( /[,;]\s*/ ).each do |pair|
118:             Arrow::Logger[self].debug "  Found pair %p" % [ pair ]
119:             key, valstr = pair.split( /=/, 2 ).collect {|s| s.strip }
120:             
121:             case key
122:             when CookiePath
123:                 Arrow::Logger[self].debug "    -> cookie-path %p" % [ valstr ]
124:                 cookies.last.path = dequote( valstr ) unless cookies.empty?
125: 
126:             when CookieDomain
127:                 Arrow::Logger[self].debug "    -> cookie-domain %p" % [ valstr ]
128:                 cookies.last.domain = dequote( valstr ) unless cookies.empty?
129: 
130:             when HTTPToken
131:                 values = parse_valuestring( valstr )
132:                 Arrow::Logger[self].debug "    -> cookie-values %p" % [ values ]
133:                 cookies << new( key, values, :version => version )
134:                 
135:             else
136:                 Arrow::Logger[self].warning \
137:                     "Malformed cookie header %p: %p is not a valid token; ignoring" %
138:                     [ header, key ]
139:             end
140:         end
141: 
142:         # Turn the array into a Hash, ignoring all but the first instance of
143:         # a cookie with the same name
144:         return cookies.inject({}) do |hash,cookie|
145:             hash[cookie.name] = cookie unless hash.key?( cookie.name )
146:             hash
147:         end
148:     end
parse_valuestring( valstr ) click to toggle source

Parse a cookie value string, returning an Array of Strings

    # File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 54
54:     def self::parse_valuestring( valstr )
55:         return [] unless valstr
56:         valstr = dequote( valstr )
57: 
58:         return valstr.split('&').collect{|str| URI.unescape(str) }
59:     end

Public Instance Methods

domain=( newdomain ) click to toggle source

Set the domain for which the cookie is valid.

     # File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 233
233:     def domain=( newdomain )
234:         newdomain = ".#{newdomain}" unless newdomain[0] == ?.
235:         @domain = newdomain.dup
236:     end
eql?( other_cookie ) click to toggle source

Return true if other_cookie has the same name as the receiver.

     # File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 301
301:     def eql?( other_cookie )
302:         return (self.name == other_cookie.name) ? true : false
303:     end
expire!() click to toggle source

Set the cookie expiration to a time in the past

     # File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 277
277:     def expire!
278:         self.expires = Time.at(0)
279:     end
expires=( time ) click to toggle source

Set the cookie‘s expires field. The value can be either a Time object or a String in any of the following formats:

+30s:30 seconds from now
+10m:ten minutes from now
+1h:one hour from now
-1d:yesterday (i.e. "ASAP!")
now:immediately
+3M:in three months
+10y:in ten years time
Thursday, 25-Apr-1999 00:40:33 GMT:at the indicated time & date

     # File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 257
257:     def expires=( time )
258:         case time
259:         when NilClass
260:             @expires = nil
261:             
262:         when Date
263:             @expires = Time.parse( time.ctime )
264:             
265:         when Time
266:             @expires = time
267:             
268:         else
269:             @expires = parse_time_delta( time )
270:         end
271:     rescue => err
272:         raise err, caller(1)
273:     end
hash() click to toggle source

Generate a Fixnum hash value for this object. Uses the hash of the cookie‘s name.

     # File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 307
307:     def hash
308:         return self.name.hash
309:     end
max_age=( delta_seconds ) click to toggle source

Set the lifetime of the cookie. The value is a decimal non-negative integer. After delta_seconds seconds elapse, the client should discard the cookie. A value of zero means the cookie should be discarded immediately.

     # File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 227
227:     def max_age=( delta_seconds )
228:         @max_age = Integer( delta_seconds )
229:     end
secure?() click to toggle source

Returns true if the secure flag is set

     # File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 219
219:     def secure?
220:         return @secure ? true : false
221:     end
to_s() click to toggle source

Return the cookie as a String

     # File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 284
284:     def to_s
285:         rval = "%s=%s" % [ self.name, make_valuestring(self.values) ]
286: 
287:         rval << make_field( "Version", self.version ) if self.version.nonzero?
288:         rval << make_field( "Domain", self.domain )
289:         rval << make_field( "Expires", make_cookiedate(self.expires) ) if self.expires
290:         rval << make_field( "Max-Age", self.max_age )
291:         rval << make_field( "Comment", self.comment )
292:         rval << make_field( "Path", self.path )
293: 
294:         rval << "; " << "Secure" if self.secure?
295: 
296:         return rval
297:     end
value() click to toggle source

Return the first value stored in the cookie as a String.

     # File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 213
213:     def value
214:         @values.first
215:     end

secsequence

--- SEC00037

seccomment

--- ""

attributes

--- 
- name: comment
  rw: RW
  a_desc: |+
    
    Because cookies can contain private information about a user, the <a
    href="Cookie.html">Cookie</a> attribute allows an origin server to document
    its intended use of a cookie. The user can inspect the information to
    decide whether to initiate or continue a session with this cookie.
    
- name: domain
  rw: R
  a_desc: |+
    
    The domain the cookie belongs to
    
- name: expires
  rw: R
  a_desc: |+
    
    The cookie&#8216;s expiration (a Time object)
    
- name: max_age
  rw: R
  a_desc: |+
    
    The lifetime of the cookie, in seconds.
    
- name: name
  rw: RW
  a_desc: |+
    
    The name of the cookie
    
- name: path
  rw: RW
  a_desc: |+
    
    The path the cookie applies to
    
- name: secure
  rw: W
  a_desc: |+
    
    The cookie&#8216;s &#8216;secure&#8217; flag.
    
- name: values
  rw: RW
  a_desc: |+
    
    The Array of cookie values
    
- name: version
  rw: RW
  a_desc: |+
    
    The cookie version. 0 (the default) is fine for most uses
    

method_list

--- 
- methods: 
  - visibility: public
    aref: M000539
    name: dequote
    sourcecode: "    <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 48</span>\n\
      48:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">dequote</span>( <span class=\"ruby-identifier\">string</span> )\n\
      49:         <span class=\"ruby-regexp re\">/^&quot;((?:[^&quot;]+|\\\\.)*)&quot;/</span>.<span class=\"ruby-identifier\">match</span>( <span class=\"ruby-identifier\">string</span> ) <span class=\"ruby-operator\">?</span> <span class=\"ruby-identifier\">$1</span> <span class=\"ruby-operator\">:</span> <span class=\"ruby-identifier\">string</span>.<span class=\"ruby-identifier\">dup</span>\n\
      50:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Strip surrounding double quotes from a copy of the specified string and
      return it.
      </p>
    params: ( string )
  - visibility: public
    aref: M000542
    name: new
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 157</span>\n\
      157:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">initialize</span>( <span class=\"ruby-identifier\">name</span>, <span class=\"ruby-identifier\">values</span>, <span class=\"ruby-identifier\">options</span>={} )\n\
      158:         <span class=\"ruby-identifier\">values</span> = [ <span class=\"ruby-identifier\">values</span> ] <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">values</span>.<span class=\"ruby-identifier\">is_a?</span>( <span class=\"ruby-constant\">Array</span> )\n\
      159:         <span class=\"ruby-ivar\">@name</span> = <span class=\"ruby-identifier\">name</span>\n\
      160:         <span class=\"ruby-ivar\">@values</span> = <span class=\"ruby-identifier\">values</span>\n\
      161: \n\
      162:         <span class=\"ruby-ivar\">@domain</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
      163:         <span class=\"ruby-ivar\">@path</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
      164:         <span class=\"ruby-ivar\">@secure</span> = <span class=\"ruby-keyword kw\">false</span>\n\
      165:         <span class=\"ruby-ivar\">@comment</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
      166:         <span class=\"ruby-ivar\">@max_age</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
      167:         <span class=\"ruby-ivar\">@expires</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
      168:         <span class=\"ruby-ivar\">@version</span> = <span class=\"ruby-value\">0</span>\n\
      169:         \n\
      170:         <span class=\"ruby-identifier\">options</span>.<span class=\"ruby-identifier\">each</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">meth</span>, <span class=\"ruby-identifier\">val</span><span class=\"ruby-operator\">|</span>\n\
      171:             <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">__send__</span>( <span class=\"ruby-node\">&quot;#{meth}=&quot;</span>, <span class=\"ruby-identifier\">val</span> )\n\
      172:         <span class=\"ruby-keyword kw\">end</span>\n\
      173:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Create a <a href="Cookie.html#M000542">new</a> <a
      href="Cookie.html">Arrow::Cookie</a> object with the specified
      <tt>name</tt> and <tt>values</tt>.
      </p>
    params: ( name, values, options={} )
  - visibility: public
    aref: M000541
    name: parse
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 102</span>\n\
      102:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">parse</span>( <span class=\"ruby-identifier\">header</span> )\n\
      103:         <span class=\"ruby-keyword kw\">return</span> {} <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">header</span>.<span class=\"ruby-identifier\">nil?</span> <span class=\"ruby-keyword kw\">or</span> <span class=\"ruby-identifier\">header</span>.<span class=\"ruby-identifier\">empty?</span>\n\
      104:         <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Logger</span>[<span class=\"ruby-keyword kw\">self</span>].<span class=\"ruby-identifier\">debug</span> <span class=\"ruby-value str\">&quot;Parsing cookie header: %p&quot;</span> <span class=\"ruby-operator\">%</span> [ <span class=\"ruby-identifier\">header</span> ]\n\
      105:         <span class=\"ruby-identifier\">cookies</span> = []\n\
      106:         <span class=\"ruby-identifier\">version</span> = <span class=\"ruby-value\">0</span>\n\
      107:         <span class=\"ruby-identifier\">header</span> = <span class=\"ruby-identifier\">header</span>.<span class=\"ruby-identifier\">strip</span>\n\
      108: \n\
      109:         <span class=\"ruby-comment cmt\"># &quot;$Version&quot; = value</span>\n\
      110:         <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-constant\">CookieVersion</span>.<span class=\"ruby-identifier\">match</span>( <span class=\"ruby-identifier\">header</span> )\n\
      111:             <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Logger</span>[<span class=\"ruby-keyword kw\">self</span>].<span class=\"ruby-identifier\">debug</span> <span class=\"ruby-value str\">&quot;  Found cookie version %p&quot;</span> <span class=\"ruby-operator\">%</span> [ <span class=\"ruby-identifier\">$1</span> ]\n\
      112:             <span class=\"ruby-identifier\">version</span> = <span class=\"ruby-constant\">Integer</span>( <span class=\"ruby-identifier\">dequote</span>(<span class=\"ruby-identifier\">$1</span>) )\n\
      113:             <span class=\"ruby-identifier\">header</span>.<span class=\"ruby-identifier\">slice!</span>( <span class=\"ruby-constant\">CookieVersion</span> )\n\
      114:         <span class=\"ruby-keyword kw\">end</span>\n\
      115: \n\
      116:         <span class=\"ruby-comment cmt\"># 1*((&quot;;&quot; | &quot;,&quot;) NAME &quot;=&quot; VALUE [&quot;;&quot; path] [&quot;;&quot; domain])</span>\n\
      117:         <span class=\"ruby-identifier\">header</span>.<span class=\"ruby-identifier\">split</span>( <span class=\"ruby-regexp re\">/[,;]\\s*/</span> ).<span class=\"ruby-identifier\">each</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">pair</span><span class=\"ruby-operator\">|</span>\n\
      118:             <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Logger</span>[<span class=\"ruby-keyword kw\">self</span>].<span class=\"ruby-identifier\">debug</span> <span class=\"ruby-value str\">&quot;  Found pair %p&quot;</span> <span class=\"ruby-operator\">%</span> [ <span class=\"ruby-identifier\">pair</span> ]\n\
      119:             <span class=\"ruby-identifier\">key</span>, <span class=\"ruby-identifier\">valstr</span> = <span class=\"ruby-identifier\">pair</span>.<span class=\"ruby-identifier\">split</span>( <span class=\"ruby-regexp re\">/=/</span>, <span class=\"ruby-value\">2</span> ).<span class=\"ruby-identifier\">collect</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">s</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">s</span>.<span class=\"ruby-identifier\">strip</span> }\n\
      120:             \n\
      121:             <span class=\"ruby-keyword kw\">case</span> <span class=\"ruby-identifier\">key</span>\n\
      122:             <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-constant\">CookiePath</span>\n\
      123:                 <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Logger</span>[<span class=\"ruby-keyword kw\">self</span>].<span class=\"ruby-identifier\">debug</span> <span class=\"ruby-value str\">&quot;    -&gt; cookie-path %p&quot;</span> <span class=\"ruby-operator\">%</span> [ <span class=\"ruby-identifier\">valstr</span> ]\n\
      124:                 <span class=\"ruby-identifier\">cookies</span>.<span class=\"ruby-identifier\">last</span>.<span class=\"ruby-identifier\">path</span> = <span class=\"ruby-identifier\">dequote</span>( <span class=\"ruby-identifier\">valstr</span> ) <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">cookies</span>.<span class=\"ruby-identifier\">empty?</span>\n\
      125: \n\
      126:             <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-constant\">CookieDomain</span>\n\
      127:                 <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Logger</span>[<span class=\"ruby-keyword kw\">self</span>].<span class=\"ruby-identifier\">debug</span> <span class=\"ruby-value str\">&quot;    -&gt; cookie-domain %p&quot;</span> <span class=\"ruby-operator\">%</span> [ <span class=\"ruby-identifier\">valstr</span> ]\n\
      128:                 <span class=\"ruby-identifier\">cookies</span>.<span class=\"ruby-identifier\">last</span>.<span class=\"ruby-identifier\">domain</span> = <span class=\"ruby-identifier\">dequote</span>( <span class=\"ruby-identifier\">valstr</span> ) <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">cookies</span>.<span class=\"ruby-identifier\">empty?</span>\n\
      129: \n\
      130:             <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-constant\">HTTPToken</span>\n\
      131:                 <span class=\"ruby-identifier\">values</span> = <span class=\"ruby-identifier\">parse_valuestring</span>( <span class=\"ruby-identifier\">valstr</span> )\n\
      132:                 <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Logger</span>[<span class=\"ruby-keyword kw\">self</span>].<span class=\"ruby-identifier\">debug</span> <span class=\"ruby-value str\">&quot;    -&gt; cookie-values %p&quot;</span> <span class=\"ruby-operator\">%</span> [ <span class=\"ruby-identifier\">values</span> ]\n\
      133:                 <span class=\"ruby-identifier\">cookies</span> <span class=\"ruby-operator\">&lt;&lt;</span> <span class=\"ruby-identifier\">new</span>( <span class=\"ruby-identifier\">key</span>, <span class=\"ruby-identifier\">values</span>, <span class=\"ruby-identifier\">:version</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">version</span> )\n\
      134:                 \n\
      135:             <span class=\"ruby-keyword kw\">else</span>\n\
      136:                 <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Logger</span>[<span class=\"ruby-keyword kw\">self</span>].<span class=\"ruby-identifier\">warning</span> \\\n\
      137:                     <span class=\"ruby-value str\">&quot;Malformed cookie header %p: %p is not a valid token; ignoring&quot;</span> <span class=\"ruby-operator\">%</span>\n\
      138:                     [ <span class=\"ruby-identifier\">header</span>, <span class=\"ruby-identifier\">key</span> ]\n\
      139:             <span class=\"ruby-keyword kw\">end</span>\n\
      140:         <span class=\"ruby-keyword kw\">end</span>\n\
      141: \n\
      142:         <span class=\"ruby-comment cmt\"># Turn the array into a Hash, ignoring all but the first instance of</span>\n\
      143:         <span class=\"ruby-comment cmt\"># a cookie with the same name</span>\n\
      144:         <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">cookies</span>.<span class=\"ruby-identifier\">inject</span>({}) <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">hash</span>,<span class=\"ruby-identifier\">cookie</span><span class=\"ruby-operator\">|</span>\n\
      145:             <span class=\"ruby-identifier\">hash</span>[<span class=\"ruby-identifier\">cookie</span>.<span class=\"ruby-identifier\">name</span>] = <span class=\"ruby-identifier\">cookie</span> <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">hash</span>.<span class=\"ruby-identifier\">key?</span>( <span class=\"ruby-identifier\">cookie</span>.<span class=\"ruby-identifier\">name</span> )\n\
      146:             <span class=\"ruby-identifier\">hash</span>\n\
      147:         <span class=\"ruby-keyword kw\">end</span>\n\
      148:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Parse the specified &#8216;<a href="Cookie.html">Cookie</a>:&#8217;
      <tt>header</tt> <a href="Cookie.html#M000543">value</a> and return a Hash
      of one or more <a href="Cookie.html#M000542">new</a> <a
      href="Cookie.html">Arrow::Cookie</a> objects, keyed by name.
      </p>
    params: ( header )
  - visibility: public
    aref: M000540
    name: parse_valuestring
    sourcecode: "    <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 54</span>\n\
      54:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">parse_valuestring</span>( <span class=\"ruby-identifier\">valstr</span> )\n\
      55:         <span class=\"ruby-keyword kw\">return</span> [] <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">valstr</span>\n\
      56:         <span class=\"ruby-identifier\">valstr</span> = <span class=\"ruby-identifier\">dequote</span>( <span class=\"ruby-identifier\">valstr</span> )\n\
      57: \n\
      58:         <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">valstr</span>.<span class=\"ruby-identifier\">split</span>(<span class=\"ruby-value str\">'&amp;'</span>).<span class=\"ruby-identifier\">collect</span>{<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">str</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-constant\">URI</span>.<span class=\"ruby-identifier\">unescape</span>(<span class=\"ruby-identifier\">str</span>) }\n\
      59:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Parse a cookie <a href="Cookie.html#M000543">value</a> string, returning an
      Array of Strings
      </p>
    params: ( valstr )
  category: Class
  type: Public
- methods: 
  - visibility: public
    aref: M000546
    name: domain=
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 233</span>\n\
      233:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">domain=</span>( <span class=\"ruby-identifier\">newdomain</span> )\n\
      234:         <span class=\"ruby-identifier\">newdomain</span> = <span class=\"ruby-node\">&quot;.#{newdomain}&quot;</span> <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">newdomain</span>[<span class=\"ruby-value\">0</span>] <span class=\"ruby-operator\">==</span> <span class=\"ruby-value\">?.</span>\n\
      235:         <span class=\"ruby-ivar\">@domain</span> = <span class=\"ruby-identifier\">newdomain</span>.<span class=\"ruby-identifier\">dup</span>\n\
      236:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Set the domain for which the cookie is valid.
      </p>
    params: ( newdomain )
  - visibility: public
    aref: M000550
    name: eql?
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 301</span>\n\
      301:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">eql?</span>( <span class=\"ruby-identifier\">other_cookie</span> )\n\
      302:         <span class=\"ruby-keyword kw\">return</span> (<span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">name</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-identifier\">other_cookie</span>.<span class=\"ruby-identifier\">name</span>) <span class=\"ruby-operator\">?</span> <span class=\"ruby-keyword kw\">true</span> <span class=\"ruby-operator\">:</span> <span class=\"ruby-keyword kw\">false</span>\n\
      303:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Return <tt>true</tt> if other_cookie has the same name as the receiver.
      </p>
    params: ( other_cookie )
  - visibility: public
    aref: M000548
    name: expire!
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 277</span>\n\
      277:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">expire!</span>\n\
      278:         <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">expires</span> = <span class=\"ruby-constant\">Time</span>.<span class=\"ruby-identifier\">at</span>(<span class=\"ruby-value\">0</span>)\n\
      279:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Set the cookie expiration to a time in the past
      </p>
    params: ()
  - visibility: public
    aref: M000547
    name: expires=
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 257</span>\n\
      257:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">expires=</span>( <span class=\"ruby-identifier\">time</span> )\n\
      258:         <span class=\"ruby-keyword kw\">case</span> <span class=\"ruby-identifier\">time</span>\n\
      259:         <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-constant\">NilClass</span>\n\
      260:             <span class=\"ruby-ivar\">@expires</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
      261:             \n\
      262:         <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-constant\">Date</span>\n\
      263:             <span class=\"ruby-ivar\">@expires</span> = <span class=\"ruby-constant\">Time</span>.<span class=\"ruby-identifier\">parse</span>( <span class=\"ruby-identifier\">time</span>.<span class=\"ruby-identifier\">ctime</span> )\n\
      264:             \n\
      265:         <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-constant\">Time</span>\n\
      266:             <span class=\"ruby-ivar\">@expires</span> = <span class=\"ruby-identifier\">time</span>\n\
      267:             \n\
      268:         <span class=\"ruby-keyword kw\">else</span>\n\
      269:             <span class=\"ruby-ivar\">@expires</span> = <span class=\"ruby-identifier\">parse_time_delta</span>( <span class=\"ruby-identifier\">time</span> )\n\
      270:         <span class=\"ruby-keyword kw\">end</span>\n\
      271:     <span class=\"ruby-keyword kw\">rescue</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">err</span>\n\
      272:         <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-identifier\">err</span>, <span class=\"ruby-identifier\">caller</span>(<span class=\"ruby-value\">1</span>)\n\
      273:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Set the cookie&#8216;s expires field. The <a
      href="Cookie.html#M000543">value</a> can be either a Time object or a
      String in any of the following formats:
      </p>
      <table>
      <tr><td valign="top">+30s:</td><td>30 seconds from now
      
      </td></tr>
      <tr><td valign="top">+10m:</td><td>ten minutes from now
      
      </td></tr>
      <tr><td valign="top">+1h:</td><td>one hour from now
      
      </td></tr>
      <tr><td valign="top">-1d:</td><td>yesterday (i.e. &quot;ASAP!&quot;)
      
      </td></tr>
      <tr><td valign="top">now:</td><td>immediately
      
      </td></tr>
      <tr><td valign="top">+3M:</td><td>in three months
      
      </td></tr>
      <tr><td valign="top">+10y:</td><td>in ten years time
      
      </td></tr>
      <tr><td valign="top">Thursday, 25-Apr-1999 00:40:33 GMT:</td><td>at the indicated time &amp; date
      
      </td></tr>
      </table>
    params: ( time )
  - visibility: public
    aref: M000551
    name: hash
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 307</span>\n\
      307:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">hash</span>\n\
      308:         <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">name</span>.<span class=\"ruby-identifier\">hash</span>\n\
      309:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Generate a Fixnum <a href="Cookie.html#M000551">hash</a> <a
      href="Cookie.html#M000543">value</a> for this object. Uses the <a
      href="Cookie.html#M000551">hash</a> of the cookie&#8216;s name.
      </p>
    params: ()
  - visibility: public
    aref: M000545
    name: max_age=
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 227</span>\n\
      227:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">max_age=</span>( <span class=\"ruby-identifier\">delta_seconds</span> )\n\
      228:         <span class=\"ruby-ivar\">@max_age</span> = <span class=\"ruby-constant\">Integer</span>( <span class=\"ruby-identifier\">delta_seconds</span> )\n\
      229:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Set the lifetime of the cookie. The <a href="Cookie.html#M000543">value</a>
      is a decimal non-negative integer. After <tt>delta_seconds</tt> seconds
      elapse, the client should discard the cookie. A <a
      href="Cookie.html#M000543">value</a> of zero means the cookie should be
      discarded immediately.
      </p>
    params: ( delta_seconds )
  - visibility: public
    aref: M000544
    name: secure?
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 219</span>\n\
      219:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">secure?</span>\n\
      220:         <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-ivar\">@secure</span> <span class=\"ruby-operator\">?</span> <span class=\"ruby-keyword kw\">true</span> <span class=\"ruby-operator\">:</span> <span class=\"ruby-keyword kw\">false</span>\n\
      221:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Returns <tt>true</tt> if the secure flag is set
      </p>
    params: ()
  - visibility: public
    aref: M000549
    name: to_s
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 284</span>\n\
      284:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">to_s</span>\n\
      285:         <span class=\"ruby-identifier\">rval</span> = <span class=\"ruby-value str\">&quot;%s=%s&quot;</span> <span class=\"ruby-operator\">%</span> [ <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">name</span>, <span class=\"ruby-identifier\">make_valuestring</span>(<span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">values</span>) ]\n\
      286: \n\
      287:         <span class=\"ruby-identifier\">rval</span> <span class=\"ruby-operator\">&lt;&lt;</span> <span class=\"ruby-identifier\">make_field</span>( <span class=\"ruby-value str\">&quot;Version&quot;</span>, <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">version</span> ) <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">version</span>.<span class=\"ruby-identifier\">nonzero?</span>\n\
      288:         <span class=\"ruby-identifier\">rval</span> <span class=\"ruby-operator\">&lt;&lt;</span> <span class=\"ruby-identifier\">make_field</span>( <span class=\"ruby-value str\">&quot;Domain&quot;</span>, <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">domain</span> )\n\
      289:         <span class=\"ruby-identifier\">rval</span> <span class=\"ruby-operator\">&lt;&lt;</span> <span class=\"ruby-identifier\">make_field</span>( <span class=\"ruby-value str\">&quot;Expires&quot;</span>, <span class=\"ruby-identifier\">make_cookiedate</span>(<span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">expires</span>) ) <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">expires</span>\n\
      290:         <span class=\"ruby-identifier\">rval</span> <span class=\"ruby-operator\">&lt;&lt;</span> <span class=\"ruby-identifier\">make_field</span>( <span class=\"ruby-value str\">&quot;Max-Age&quot;</span>, <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">max_age</span> )\n\
      291:         <span class=\"ruby-identifier\">rval</span> <span class=\"ruby-operator\">&lt;&lt;</span> <span class=\"ruby-identifier\">make_field</span>( <span class=\"ruby-value str\">&quot;Comment&quot;</span>, <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">comment</span> )\n\
      292:         <span class=\"ruby-identifier\">rval</span> <span class=\"ruby-operator\">&lt;&lt;</span> <span class=\"ruby-identifier\">make_field</span>( <span class=\"ruby-value str\">&quot;Path&quot;</span>, <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">path</span> )\n\
      293: \n\
      294:         <span class=\"ruby-identifier\">rval</span> <span class=\"ruby-operator\">&lt;&lt;</span> <span class=\"ruby-value str\">&quot;; &quot;</span> <span class=\"ruby-operator\">&lt;&lt;</span> <span class=\"ruby-value str\">&quot;Secure&quot;</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">secure?</span>\n\
      295: \n\
      296:         <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">rval</span>\n\
      297:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Return the cookie as a String
      </p>
    params: ()
  - visibility: public
    aref: M000543
    name: value
    sourcecode: "     <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/cookie.rb, line 213</span>\n\
      213:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">value</span>\n\
      214:         <span class=\"ruby-ivar\">@values</span>.<span class=\"ruby-identifier\">first</span>\n\
      215:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Return the first <a href="Cookie.html#M000543">value</a> stored in the
      cookie as a String.
      </p>
    params: ()
  category: Instance
  type: Public

sectitle

--- 

constants

--- 
- name: SVNRev
  desc: |+
    
    SVN Revision
    
  value: "%q$Rev: 406 $"
- name: SVNId
  desc: |+
    
    SVN Id
    
  value: "%q$Id: cookie.rb 406 2007-07-18 17:01:59Z bbleything $"
- name: CookieDateFormat
  value: "'%a, %d-%b-%Y %H:%M:%S GMT'"
- name: CookieVersion
  desc: |
    <pre>
      RFC 2109: HTTP State Management Mechanism
    </pre>
    
    When it sends a request to an origin server, the user agent sends a <a
    href="Cookie.html">Cookie</a> request header to the origin server if it has
    cookies that are applicable to the request, based on
    
    <pre>
      * the request-host;
      * the request-URI;
      * the cookie's age.
    </pre>
    <p>
    The syntax for the header is:
    </p>
    <p>
    cookie = &quot;<a href="Cookie.html">Cookie</a>:&quot; cookie-version
    </p>
    <pre>
                               1*((&quot;;&quot; | &quot;,&quot;) cookie-value)
    </pre>
    <p>
    cookie-<a href="Cookie.html#M000543">value</a> = NAME &quot;=&quot; VALUE
    [&quot;;&quot; path] [&quot;;&quot; domain] cookie-version =
    &quot;$Version&quot; &quot;=&quot; <a href="Cookie.html#M000543">value</a>
    NAME = attr VALUE = <a href="Cookie.html#M000543">value</a> path =
    &quot;$<a href="../Path.html">Path</a>&quot; &quot;=&quot; <a
    href="Cookie.html#M000543">value</a> domain = &quot;$Domain&quot;
    &quot;=&quot; <a href="Cookie.html#M000543">value</a>
    </p>

  value: /\$Version\s*=\s*(.+)\s*[,;]/
- name: CookiePath
  value: /\$Path/i
- name: CookieDomain
  value: /\$Domain/i
- name: CTLs
  desc: |
    <pre>
      RFC2068: Hypertext Transfer Protocol -- HTTP/1.1
    </pre>
    
    CTL = &lt;any US-ASCII control character
    
    <pre>
                     (octets 0 - 31) and DEL (127)&gt;
    </pre>
    <p>
    token = 1*&lt;any CHAR except CTLs or tspecials&gt;
    </p>
    <p>
    tspecials = &quot;(&quot; | &quot;)&quot; | &quot;&lt;&quot; |
    &quot;&gt;&quot; | &quot;@&quot;
    </p>
    <pre>
                   | &quot;,&quot; | &quot;;&quot; | &quot;:&quot; | &quot;\&quot; | &lt;&quot;&gt;
                   | &quot;/&quot; | &quot;[&quot; | &quot;]&quot; | &quot;?&quot; | &quot;=&quot;
                   | &quot;{&quot; | &quot;}&quot; | SP | HT
    </pre>

  value: "&quot;[:cntrl:]&quot;"
- name: TSpecials
  value: Regexp.quote ' &quot;(),/:;&lt;=&gt;?@[\\]{}'
- name: NonTokenChar
  value: /[#{CTLs}#{TSpecials}]/s
- name: HTTPToken
  value: /\A[^#{CTLs}#{TSpecials}]+\z/s
- name: Seconds
  desc: |+
    
    Number of seconds in the various offset types
    
  value: "{         's' =&gt; 1,         'm' =&gt; 60,         'h' =&gt; 60*60,         'd' =&gt; 60*60*24,         'M' =&gt; 60*60*24*30,         'y' =&gt; 60*60*24*365,     }"

[Validate]

Generated with the Darkfish Rdoc Generator.