518 lines
26 KiB
HTML
518 lines
26 KiB
HTML
|
<?xml version="1.0" encoding="utf-8"?>
|
||
|
<!DOCTYPE html
|
||
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
|
||
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||
|
<head>
|
||
|
<title>Class: Rack::Response</title>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
|
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
||
|
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
||
|
<script type="text/javascript">
|
||
|
// <![CDATA[
|
||
|
|
||
|
function popupCode( url ) {
|
||
|
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
||
|
}
|
||
|
|
||
|
function toggleCode( id ) {
|
||
|
if ( document.getElementById )
|
||
|
elem = document.getElementById( id );
|
||
|
else if ( document.all )
|
||
|
elem = eval( "document.all." + id );
|
||
|
else
|
||
|
return false;
|
||
|
|
||
|
elemStyle = elem.style;
|
||
|
|
||
|
if ( elemStyle.display != "block" ) {
|
||
|
elemStyle.display = "block"
|
||
|
} else {
|
||
|
elemStyle.display = "none"
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
// Make codeblocks hidden by default
|
||
|
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
||
|
|
||
|
// ]]>
|
||
|
</script>
|
||
|
|
||
|
</head>
|
||
|
<body>
|
||
|
|
||
|
|
||
|
|
||
|
<div id="classHeader">
|
||
|
<table class="header-table">
|
||
|
<tr class="top-aligned-row">
|
||
|
<td><strong>Class</strong></td>
|
||
|
<td class="class-name-in-header">Rack::Response</td>
|
||
|
</tr>
|
||
|
<tr class="top-aligned-row">
|
||
|
<td><strong>In:</strong></td>
|
||
|
<td>
|
||
|
<a href="../../files/lib/rack/response_rb.html">
|
||
|
lib/rack/response.rb
|
||
|
</a>
|
||
|
<br />
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr class="top-aligned-row">
|
||
|
<td><strong>Parent:</strong></td>
|
||
|
<td>
|
||
|
Object
|
||
|
</td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div>
|
||
|
<!-- banner header -->
|
||
|
|
||
|
<div id="bodyContent">
|
||
|
|
||
|
|
||
|
|
||
|
<div id="contextContent">
|
||
|
|
||
|
<div id="description">
|
||
|
<p>
|
||
|
<a href="Response.html">Rack::Response</a> provides a convenient interface
|
||
|
to create a <a href="../Rack.html">Rack</a> response.
|
||
|
</p>
|
||
|
<p>
|
||
|
It allows setting of headers and cookies, and provides useful defaults (a
|
||
|
OK response containing HTML).
|
||
|
</p>
|
||
|
<p>
|
||
|
You can use <a href="Response.html#M000096">Response#write</a> to
|
||
|
iteratively generate your response, but note that this is buffered by <a
|
||
|
href="Response.html">Rack::Response</a> until you call <tt><a
|
||
|
href="Response.html#M000093">finish</a></tt>. <tt><a
|
||
|
href="Response.html#M000093">finish</a></tt> however can take a block
|
||
|
inside which calls to <tt><a href="Response.html#M000096">write</a></tt>
|
||
|
are syncronous with the <a href="../Rack.html">Rack</a> response.
|
||
|
</p>
|
||
|
<p>
|
||
|
Your application‘s <tt>call</tt> should end returning <a
|
||
|
href="Response.html#M000093">Response#finish</a>.
|
||
|
</p>
|
||
|
|
||
|
</div>
|
||
|
|
||
|
|
||
|
</div>
|
||
|
|
||
|
<div id="method-list">
|
||
|
<h3 class="section-bar">Methods</h3>
|
||
|
|
||
|
<div class="name-list">
|
||
|
<a href="#M000089">[]</a>
|
||
|
<a href="#M000090">[]=</a>
|
||
|
<a href="#M000097">close</a>
|
||
|
<a href="#M000092">delete_cookie</a>
|
||
|
<a href="#M000095">each</a>
|
||
|
<a href="#M000098">empty?</a>
|
||
|
<a href="#M000093">finish</a>
|
||
|
<a href="#M000088">new</a>
|
||
|
<a href="#M000091">set_cookie</a>
|
||
|
<a href="#M000094">to_a</a>
|
||
|
<a href="#M000096">write</a>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<!-- if includes -->
|
||
|
<div id="includes">
|
||
|
<h3 class="section-bar">Included Modules</h3>
|
||
|
|
||
|
<div id="includes-list">
|
||
|
<span class="include-name"><a href="Response/Helpers.html">Helpers</a></span>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div id="section">
|
||
|
|
||
|
<div id="class-list">
|
||
|
<h3 class="section-bar">Classes and Modules</h3>
|
||
|
|
||
|
Module <a href="Response/Helpers.html" class="link">Rack::Response::Helpers</a><br />
|
||
|
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<div id="aliases-list">
|
||
|
<h3 class="section-bar">External Aliases</h3>
|
||
|
|
||
|
<div class="name-list">
|
||
|
<table summary="aliases">
|
||
|
<tr class="top-aligned-row context-row">
|
||
|
<td class="context-item-name">header</td>
|
||
|
<td>-></td>
|
||
|
<td class="context-item-value">headers</td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<div id="attribute-list">
|
||
|
<h3 class="section-bar">Attributes</h3>
|
||
|
|
||
|
<div class="name-list">
|
||
|
<table>
|
||
|
<tr class="top-aligned-row context-row">
|
||
|
<td class="context-item-name">body</td>
|
||
|
<td class="context-item-value"> [RW] </td>
|
||
|
<td class="context-item-desc"></td>
|
||
|
</tr>
|
||
|
<tr class="top-aligned-row context-row">
|
||
|
<td class="context-item-name">header</td>
|
||
|
<td class="context-item-value"> [R] </td>
|
||
|
<td class="context-item-desc"></td>
|
||
|
</tr>
|
||
|
<tr class="top-aligned-row context-row">
|
||
|
<td class="context-item-name">status</td>
|
||
|
<td class="context-item-value"> [RW] </td>
|
||
|
<td class="context-item-desc"></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
<!-- if method_list -->
|
||
|
<div id="methods">
|
||
|
<h3 class="section-bar">Public Class methods</h3>
|
||
|
|
||
|
<div id="method-M000088" class="method-detail">
|
||
|
<a name="M000088"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000088" class="method-signature">
|
||
|
<span class="method-name">new</span><span class="method-args">(body=[], status=200, header={}) {|self if block_given?| ...}</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000088-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000088-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/response.rb, line 19</span>
|
||
|
19: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">body</span>=[], <span class="ruby-identifier">status</span>=<span class="ruby-value">200</span>, <span class="ruby-identifier">header</span>={}, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
||
|
20: <span class="ruby-ivar">@status</span> = <span class="ruby-identifier">status</span>
|
||
|
21: <span class="ruby-ivar">@header</span> = <span class="ruby-constant">Utils</span><span class="ruby-operator">::</span><span class="ruby-constant">HeaderHash</span>.<span class="ruby-identifier">new</span>({<span class="ruby-value str">"Content-Type"</span> =<span class="ruby-operator">></span> <span class="ruby-value str">"text/html"</span>}.
|
||
|
22: <span class="ruby-identifier">merge</span>(<span class="ruby-identifier">header</span>))
|
||
|
23:
|
||
|
24: <span class="ruby-ivar">@writer</span> = <span class="ruby-identifier">lambda</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@body</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">x</span> }
|
||
|
25: <span class="ruby-ivar">@block</span> = <span class="ruby-keyword kw">nil</span>
|
||
|
26: <span class="ruby-ivar">@length</span> = <span class="ruby-value">0</span>
|
||
|
27:
|
||
|
28: <span class="ruby-ivar">@body</span> = []
|
||
|
29:
|
||
|
30: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">body</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:to_str</span>
|
||
|
31: <span class="ruby-identifier">write</span> <span class="ruby-identifier">body</span>.<span class="ruby-identifier">to_str</span>
|
||
|
32: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">body</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:each</span>)
|
||
|
33: <span class="ruby-identifier">body</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">part</span><span class="ruby-operator">|</span>
|
||
|
34: <span class="ruby-identifier">write</span> <span class="ruby-identifier">part</span>.<span class="ruby-identifier">to_s</span>
|
||
|
35: }
|
||
|
36: <span class="ruby-keyword kw">else</span>
|
||
|
37: <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">"stringable or iterable required"</span>
|
||
|
38: <span class="ruby-keyword kw">end</span>
|
||
|
39:
|
||
|
40: <span class="ruby-keyword kw">yield</span> <span class="ruby-keyword kw">self</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
||
|
41: <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<h3 class="section-bar">Public Instance methods</h3>
|
||
|
|
||
|
<div id="method-M000089" class="method-detail">
|
||
|
<a name="M000089"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000089" class="method-signature">
|
||
|
<span class="method-name">[]</span><span class="method-args">(key)</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000089-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000089-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/response.rb, line 46</span>
|
||
|
46: <span class="ruby-keyword kw">def</span> <span class="ruby-operator">[]</span>(<span class="ruby-identifier">key</span>)
|
||
|
47: <span class="ruby-identifier">header</span>[<span class="ruby-identifier">key</span>]
|
||
|
48: <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div id="method-M000090" class="method-detail">
|
||
|
<a name="M000090"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000090" class="method-signature">
|
||
|
<span class="method-name">[]=</span><span class="method-args">(key, value)</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000090-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000090-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/response.rb, line 50</span>
|
||
|
50: <span class="ruby-keyword kw">def</span> <span class="ruby-operator">[]=</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>)
|
||
|
51: <span class="ruby-identifier">header</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span>
|
||
|
52: <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div id="method-M000097" class="method-detail">
|
||
|
<a name="M000097"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000097" class="method-signature">
|
||
|
<span class="method-name">close</span><span class="method-args">()</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000097-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000097-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/response.rb, line 122</span>
|
||
|
122: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">close</span>
|
||
|
123: <span class="ruby-identifier">body</span>.<span class="ruby-identifier">close</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">body</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:close</span>)
|
||
|
124: <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div id="method-M000092" class="method-detail">
|
||
|
<a name="M000092"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000092" class="method-signature">
|
||
|
<span class="method-name">delete_cookie</span><span class="method-args">(key, value={})</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000092-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000092-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/response.rb, line 81</span>
|
||
|
81: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete_cookie</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>={})
|
||
|
82: <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Array</span> <span class="ruby-operator">===</span> <span class="ruby-keyword kw">self</span>[<span class="ruby-value str">"Set-Cookie"</span>]
|
||
|
83: <span class="ruby-keyword kw">self</span>[<span class="ruby-value str">"Set-Cookie"</span>] = [<span class="ruby-keyword kw">self</span>[<span class="ruby-value str">"Set-Cookie"</span>]].<span class="ruby-identifier">compact</span>
|
||
|
84: <span class="ruby-keyword kw">end</span>
|
||
|
85:
|
||
|
86: <span class="ruby-keyword kw">self</span>[<span class="ruby-value str">"Set-Cookie"</span>].<span class="ruby-identifier">reject!</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">cookie</span><span class="ruby-operator">|</span>
|
||
|
87: <span class="ruby-identifier">cookie</span> <span class="ruby-operator">=~</span> <span class="ruby-node">/\A#{Utils.escape(key)}=/</span>
|
||
|
88: }
|
||
|
89:
|
||
|
90: <span class="ruby-identifier">set_cookie</span>(<span class="ruby-identifier">key</span>,
|
||
|
91: {<span class="ruby-identifier">:value</span> =<span class="ruby-operator">></span> <span class="ruby-value str">''</span>, <span class="ruby-identifier">:path</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">:domain</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">nil</span>,
|
||
|
92: <span class="ruby-identifier">:expires</span> =<span class="ruby-operator">></span> <span class="ruby-constant">Time</span>.<span class="ruby-identifier">at</span>(<span class="ruby-value">0</span>) }.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">value</span>))
|
||
|
93: <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div id="method-M000095" class="method-detail">
|
||
|
<a name="M000095"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000095" class="method-signature">
|
||
|
<span class="method-name">each</span><span class="method-args">(&callback)</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000095-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000095-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/response.rb, line 109</span>
|
||
|
109: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">each</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">callback</span>)
|
||
|
110: <span class="ruby-ivar">@body</span>.<span class="ruby-identifier">each</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">callback</span>)
|
||
|
111: <span class="ruby-ivar">@writer</span> = <span class="ruby-identifier">callback</span>
|
||
|
112: <span class="ruby-ivar">@block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-keyword kw">self</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@block</span>
|
||
|
113: <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div id="method-M000098" class="method-detail">
|
||
|
<a name="M000098"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000098" class="method-signature">
|
||
|
<span class="method-name">empty?</span><span class="method-args">()</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000098-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000098-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/response.rb, line 126</span>
|
||
|
126: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">empty?</span>
|
||
|
127: <span class="ruby-ivar">@block</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-operator">&&</span> <span class="ruby-ivar">@body</span>.<span class="ruby-identifier">empty?</span>
|
||
|
128: <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div id="method-M000093" class="method-detail">
|
||
|
<a name="M000093"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000093" class="method-signature">
|
||
|
<span class="method-name">finish</span><span class="method-args">(&block)</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000093-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000093-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/response.rb, line 96</span>
|
||
|
96: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">finish</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
||
|
97: <span class="ruby-ivar">@block</span> = <span class="ruby-identifier">block</span>
|
||
|
98:
|
||
|
99: <span class="ruby-keyword kw">if</span> [<span class="ruby-value">204</span>, <span class="ruby-value">304</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">status</span>.<span class="ruby-identifier">to_i</span>)
|
||
|
100: <span class="ruby-identifier">header</span>.<span class="ruby-identifier">delete</span> <span class="ruby-value str">"Content-Type"</span>
|
||
|
101: [<span class="ruby-identifier">status</span>.<span class="ruby-identifier">to_i</span>, <span class="ruby-identifier">header</span>.<span class="ruby-identifier">to_hash</span>, []]
|
||
|
102: <span class="ruby-keyword kw">else</span>
|
||
|
103: <span class="ruby-identifier">header</span>[<span class="ruby-value str">"Content-Length"</span>] <span class="ruby-operator">||=</span> <span class="ruby-ivar">@length</span>.<span class="ruby-identifier">to_s</span>
|
||
|
104: [<span class="ruby-identifier">status</span>.<span class="ruby-identifier">to_i</span>, <span class="ruby-identifier">header</span>.<span class="ruby-identifier">to_hash</span>, <span class="ruby-keyword kw">self</span>]
|
||
|
105: <span class="ruby-keyword kw">end</span>
|
||
|
106: <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div id="method-M000091" class="method-detail">
|
||
|
<a name="M000091"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000091" class="method-signature">
|
||
|
<span class="method-name">set_cookie</span><span class="method-args">(key, value)</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000091-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000091-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/response.rb, line 54</span>
|
||
|
54: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_cookie</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>)
|
||
|
55: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">value</span>
|
||
|
56: <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Hash</span>
|
||
|
57: <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>]
|
||
|
58: <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>]
|
||
|
59: <span class="ruby-comment cmt"># According to RFC 2109, we need dashes here.</span>
|
||
|
60: <span class="ruby-comment cmt"># N.B.: cgi.rb uses spaces...</span>
|
||
|
61: <span class="ruby-identifier">expires</span> = <span class="ruby-value str">"; expires="</span> <span class="ruby-operator">+</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>.
|
||
|
62: <span class="ruby-identifier">strftime</span>(<span class="ruby-value str">"%a, %d-%b-%Y %H:%M:%S GMT"</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>[<span class="ruby-identifier">:expires</span>]
|
||
|
63: <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>]
|
||
|
64: <span class="ruby-identifier">value</span> = <span class="ruby-identifier">value</span>[<span class="ruby-identifier">:value</span>]
|
||
|
65: <span class="ruby-keyword kw">end</span>
|
||
|
66: <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>
|
||
|
67: <span class="ruby-identifier">cookie</span> = <span class="ruby-constant">Utils</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>
|
||
|
68: <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-constant">Utils</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>
|
||
|
69: <span class="ruby-node">"#{domain}#{path}#{expires}#{secure}"</span>
|
||
|
70:
|
||
|
71: <span class="ruby-keyword kw">case</span> <span class="ruby-keyword kw">self</span>[<span class="ruby-value str">"Set-Cookie"</span>]
|
||
|
72: <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Array</span>
|
||
|
73: <span class="ruby-keyword kw">self</span>[<span class="ruby-value str">"Set-Cookie"</span>] <span class="ruby-operator"><<</span> <span class="ruby-identifier">cookie</span>
|
||
|
74: <span class="ruby-keyword kw">when</span> <span class="ruby-constant">String</span>
|
||
|
75: <span class="ruby-keyword kw">self</span>[<span class="ruby-value str">"Set-Cookie"</span>] = [<span class="ruby-keyword kw">self</span>[<span class="ruby-value str">"Set-Cookie"</span>], <span class="ruby-identifier">cookie</span>]
|
||
|
76: <span class="ruby-keyword kw">when</span> <span class="ruby-keyword kw">nil</span>
|
||
|
77: <span class="ruby-keyword kw">self</span>[<span class="ruby-value str">"Set-Cookie"</span>] = <span class="ruby-identifier">cookie</span>
|
||
|
78: <span class="ruby-keyword kw">end</span>
|
||
|
79: <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div id="method-M000094" class="method-detail">
|
||
|
<a name="M000094"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<span class="method-name">to_a</span><span class="method-args">(&block)</span>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p>
|
||
|
Alias for <a href="Response.html#M000093">finish</a>
|
||
|
</p>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div id="method-M000096" class="method-detail">
|
||
|
<a name="M000096"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000096" class="method-signature">
|
||
|
<span class="method-name">write</span><span class="method-args">(str)</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000096-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000096-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/response.rb, line 115</span>
|
||
|
115: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">write</span>(<span class="ruby-identifier">str</span>)
|
||
|
116: <span class="ruby-identifier">s</span> = <span class="ruby-identifier">str</span>.<span class="ruby-identifier">to_s</span>
|
||
|
117: <span class="ruby-ivar">@length</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">size</span>
|
||
|
118: <span class="ruby-ivar">@writer</span>.<span class="ruby-identifier">call</span> <span class="ruby-identifier">s</span>
|
||
|
119: <span class="ruby-identifier">str</span>
|
||
|
120: <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
</div>
|
||
|
|
||
|
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<div id="validator-badges">
|
||
|
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
||
|
</div>
|
||
|
|
||
|
</body>
|
||
|
</html>
|