D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby18
/
lib64
/
ruby
/
gems
/
1.8
/
doc
/
rack-1.6.1
/
rdoc
/
files
/
lib
/
rack
/
utils_rb.src
/
Filename :
M000009.html
back
Copy
<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>set_cookie_header! (lib/rack/utils.rb)</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" /> </head> <body class="standalone-code"> <pre><span class="ruby-comment cmt"># File lib/rack/utils.rb, line 274</span> <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_cookie_header!</span>(<span class="ruby-identifier">header</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>) <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">value</span> <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Hash</span> <span class="ruby-identifier">domain</span> = <span class="ruby-value str">"; domain="</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">value</span>[<span class="ruby-identifier">:domain</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>[<span class="ruby-identifier">:domain</span>] <span class="ruby-identifier">path</span> = <span class="ruby-value str">"; path="</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">value</span>[<span class="ruby-identifier">:path</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>[<span class="ruby-identifier">:path</span>] <span class="ruby-identifier">max_age</span> = <span class="ruby-value str">"; max-age="</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">value</span>[<span class="ruby-identifier">:max_age</span>].<span class="ruby-identifier">to_s</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>[<span class="ruby-identifier">:max_age</span>] <span class="ruby-comment cmt"># There is an RFC mess in the area of date formatting for Cookies. Not</span> <span class="ruby-comment cmt"># only are there contradicting RFCs and examples within RFC text, but</span> <span class="ruby-comment cmt"># there are also numerous conflicting names of fields and partially</span> <span class="ruby-comment cmt"># cross-applicable specifications.</span> <span class="ruby-comment cmt">#</span> <span class="ruby-comment cmt"># These are best described in RFC 2616 3.3.1. This RFC text also</span> <span class="ruby-comment cmt"># specifies that RFC 822 as updated by RFC 1123 is preferred. That is a</span> <span class="ruby-comment cmt"># fixed length format with space-date delimeted fields.</span> <span class="ruby-comment cmt">#</span> <span class="ruby-comment cmt"># See also RFC 1123 section 5.2.14.</span> <span class="ruby-comment cmt">#</span> <span class="ruby-comment cmt"># RFC 6265 also specifies "sane-cookie-date" as RFC 1123 date, defined</span> <span class="ruby-comment cmt"># in RFC 2616 3.3.1. RFC 6265 also gives examples that clearly denote</span> <span class="ruby-comment cmt"># the space delimited format. These formats are compliant with RFC 2822.</span> <span class="ruby-comment cmt">#</span> <span class="ruby-comment cmt"># For reference, all involved RFCs are:</span> <span class="ruby-comment cmt"># RFC 822</span> <span class="ruby-comment cmt"># RFC 1123</span> <span class="ruby-comment cmt"># RFC 2109</span> <span class="ruby-comment cmt"># RFC 2616</span> <span class="ruby-comment cmt"># RFC 2822</span> <span class="ruby-comment cmt"># RFC 2965</span> <span class="ruby-comment cmt"># RFC 6265</span> <span class="ruby-identifier">expires</span> = <span class="ruby-value str">"; expires="</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">rfc2822</span>(<span class="ruby-identifier">value</span>[<span class="ruby-identifier">:expires</span>].<span class="ruby-identifier">clone</span>.<span class="ruby-identifier">gmtime</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>[<span class="ruby-identifier">:expires</span>] <span class="ruby-identifier">secure</span> = <span class="ruby-value str">"; secure"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>[<span class="ruby-identifier">:secure</span>] <span class="ruby-identifier">httponly</span> = <span class="ruby-value str">"; HttpOnly"</span> <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">value</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">:httponly</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">value</span>[<span class="ruby-identifier">:httponly</span>] <span class="ruby-operator">:</span> <span class="ruby-identifier">value</span>[<span class="ruby-identifier">:http_only</span>]) <span class="ruby-identifier">value</span> = <span class="ruby-identifier">value</span>[<span class="ruby-identifier">:value</span>] <span class="ruby-keyword kw">end</span> <span class="ruby-identifier">value</span> = [<span class="ruby-identifier">value</span>] <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Array</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">value</span> <span class="ruby-identifier">cookie</span> = <span class="ruby-identifier">escape</span>(<span class="ruby-identifier">key</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">"="</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">escape</span> <span class="ruby-identifier">v</span> }.<span class="ruby-identifier">join</span>(<span class="ruby-value str">"&"</span>) <span class="ruby-operator">+</span> <span class="ruby-node">"#{domain}#{path}#{max_age}#{expires}#{secure}#{httponly}"</span> <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">header</span>[<span class="ruby-value str">"Set-Cookie"</span>] <span class="ruby-keyword kw">when</span> <span class="ruby-keyword kw">nil</span>, <span class="ruby-value str">''</span> <span class="ruby-identifier">header</span>[<span class="ruby-value str">"Set-Cookie"</span>] = <span class="ruby-identifier">cookie</span> <span class="ruby-keyword kw">when</span> <span class="ruby-constant">String</span> <span class="ruby-identifier">header</span>[<span class="ruby-value str">"Set-Cookie"</span>] = [<span class="ruby-identifier">header</span>[<span class="ruby-value str">"Set-Cookie"</span>], <span class="ruby-identifier">cookie</span>].<span class="ruby-identifier">join</span>(<span class="ruby-value str">"\n"</span>) <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Array</span> <span class="ruby-identifier">header</span>[<span class="ruby-value str">"Set-Cookie"</span>] = (<span class="ruby-identifier">header</span>[<span class="ruby-value str">"Set-Cookie"</span>] <span class="ruby-operator">+</span> [<span class="ruby-identifier">cookie</span>]).<span class="ruby-identifier">join</span>(<span class="ruby-value str">"\n"</span>) <span class="ruby-keyword kw">end</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">end</span></pre> </body> </html>