258 lines
17 KiB
HTML
258 lines
17 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::Handler::Mongrel</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::Handler::Mongrel</td>
|
||
|
</tr>
|
||
|
<tr class="top-aligned-row">
|
||
|
<td><strong>In:</strong></td>
|
||
|
<td>
|
||
|
<a href="../../../files/lib/rack/handler/mongrel_rb.html">
|
||
|
lib/rack/handler/mongrel.rb
|
||
|
</a>
|
||
|
<br />
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr class="top-aligned-row">
|
||
|
<td><strong>Parent:</strong></td>
|
||
|
<td>
|
||
|
::Mongrel::HttpHandler
|
||
|
</td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div>
|
||
|
<!-- banner header -->
|
||
|
|
||
|
<div id="bodyContent">
|
||
|
|
||
|
|
||
|
|
||
|
<div id="contextContent">
|
||
|
|
||
|
|
||
|
|
||
|
</div>
|
||
|
|
||
|
<div id="method-list">
|
||
|
<h3 class="section-bar">Methods</h3>
|
||
|
|
||
|
<div class="name-list">
|
||
|
<a href="#M000066">new</a>
|
||
|
<a href="#M000067">process</a>
|
||
|
<a href="#M000065">run</a>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<!-- if includes -->
|
||
|
|
||
|
<div id="section">
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<!-- if method_list -->
|
||
|
<div id="methods">
|
||
|
<h3 class="section-bar">Public Class methods</h3>
|
||
|
|
||
|
<div id="method-M000066" class="method-detail">
|
||
|
<a name="M000066"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000066" class="method-signature">
|
||
|
<span class="method-name">new</span><span class="method-args">(app)</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000066-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000066-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/handler/mongrel.rb, line 35</span>
|
||
|
35: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">app</span>)
|
||
|
36: <span class="ruby-ivar">@app</span> = <span class="ruby-identifier">app</span>
|
||
|
37: <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div id="method-M000065" class="method-detail">
|
||
|
<a name="M000065"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000065" class="method-signature">
|
||
|
<span class="method-name">run</span><span class="method-args">(app, options={}) {|server if block_given?| ...}</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000065-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000065-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/handler/mongrel.rb, line 7</span>
|
||
|
7: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">run</span>(<span class="ruby-identifier">app</span>, <span class="ruby-identifier">options</span>={})
|
||
|
8: <span class="ruby-identifier">server</span> = <span class="ruby-operator">::</span><span class="ruby-constant">Mongrel</span><span class="ruby-operator">::</span><span class="ruby-constant">HttpServer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:Host</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">'0.0.0.0'</span>,
|
||
|
9: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:Port</span>] <span class="ruby-operator">||</span> <span class="ruby-value">8080</span>)
|
||
|
10: <span class="ruby-comment cmt"># Acts like Rack::URLMap, utilizing Mongrel's own path finding methods.</span>
|
||
|
11: <span class="ruby-comment cmt"># Use is similar to #run, replacing the app argument with a hash of </span>
|
||
|
12: <span class="ruby-comment cmt"># { path=>app, ... } or an instance of Rack::URLMap.</span>
|
||
|
13: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:map</span>]
|
||
|
14: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">app</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Hash</span>
|
||
|
15: <span class="ruby-identifier">app</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span>, <span class="ruby-identifier">appl</span><span class="ruby-operator">|</span>
|
||
|
16: <span class="ruby-identifier">path</span> = <span class="ruby-value str">'/'</span><span class="ruby-operator">+</span><span class="ruby-identifier">path</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">path</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value">?/</span>
|
||
|
17: <span class="ruby-identifier">server</span>.<span class="ruby-identifier">register</span>(<span class="ruby-identifier">path</span>, <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">Mongrel</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">appl</span>))
|
||
|
18: <span class="ruby-keyword kw">end</span>
|
||
|
19: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">app</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">URLMap</span>
|
||
|
20: <span class="ruby-identifier">app</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-identifier">:@mapping</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span>(<span class="ruby-identifier">host</span>, <span class="ruby-identifier">path</span>, <span class="ruby-identifier">appl</span>)<span class="ruby-operator">|</span>
|
||
|
21: <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">host</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">&&</span> <span class="ruby-operator">!</span><span class="ruby-identifier">options</span>[<span class="ruby-identifier">:Host</span>].<span class="ruby-identifier">nil?</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:Host</span>] <span class="ruby-operator">!=</span> <span class="ruby-identifier">host</span>
|
||
|
22: <span class="ruby-identifier">path</span> = <span class="ruby-value str">'/'</span><span class="ruby-operator">+</span><span class="ruby-identifier">path</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">path</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value">?/</span>
|
||
|
23: <span class="ruby-identifier">server</span>.<span class="ruby-identifier">register</span>(<span class="ruby-identifier">path</span>, <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">Mongrel</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">appl</span>))
|
||
|
24: <span class="ruby-keyword kw">end</span>
|
||
|
25: <span class="ruby-keyword kw">else</span>
|
||
|
26: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"first argument should be a Hash or URLMap"</span>
|
||
|
27: <span class="ruby-keyword kw">end</span>
|
||
|
28: <span class="ruby-keyword kw">else</span>
|
||
|
29: <span class="ruby-identifier">server</span>.<span class="ruby-identifier">register</span>(<span class="ruby-value str">'/'</span>, <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Handler</span><span class="ruby-operator">::</span><span class="ruby-constant">Mongrel</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">app</span>))
|
||
|
30: <span class="ruby-keyword kw">end</span>
|
||
|
31: <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">server</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
||
|
32: <span class="ruby-identifier">server</span>.<span class="ruby-identifier">run</span>.<span class="ruby-identifier">join</span>
|
||
|
33: <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<h3 class="section-bar">Public Instance methods</h3>
|
||
|
|
||
|
<div id="method-M000067" class="method-detail">
|
||
|
<a name="M000067"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000067" class="method-signature">
|
||
|
<span class="method-name">process</span><span class="method-args">(request, response)</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000067-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000067-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/handler/mongrel.rb, line 39</span>
|
||
|
39: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">process</span>(<span class="ruby-identifier">request</span>, <span class="ruby-identifier">response</span>)
|
||
|
40: <span class="ruby-identifier">env</span> = {}.<span class="ruby-identifier">replace</span>(<span class="ruby-identifier">request</span>.<span class="ruby-identifier">params</span>)
|
||
|
41: <span class="ruby-identifier">env</span>.<span class="ruby-identifier">delete</span> <span class="ruby-value str">"HTTP_CONTENT_TYPE"</span>
|
||
|
42: <span class="ruby-identifier">env</span>.<span class="ruby-identifier">delete</span> <span class="ruby-value str">"HTTP_CONTENT_LENGTH"</span>
|
||
|
43:
|
||
|
44: <span class="ruby-identifier">env</span>[<span class="ruby-value str">"SCRIPT_NAME"</span>] = <span class="ruby-value str">""</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">env</span>[<span class="ruby-value str">"SCRIPT_NAME"</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">"/"</span>
|
||
|
45:
|
||
|
46: <span class="ruby-identifier">env</span>.<span class="ruby-identifier">update</span>({<span class="ruby-value str">"rack.version"</span> =<span class="ruby-operator">></span> [<span class="ruby-value">0</span>,<span class="ruby-value">1</span>],
|
||
|
47: <span class="ruby-value str">"rack.input"</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">request</span>.<span class="ruby-identifier">body</span> <span class="ruby-operator">||</span> <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">""</span>),
|
||
|
48: <span class="ruby-value str">"rack.errors"</span> =<span class="ruby-operator">></span> <span class="ruby-constant">STDERR</span>,
|
||
|
49:
|
||
|
50: <span class="ruby-value str">"rack.multithread"</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">true</span>,
|
||
|
51: <span class="ruby-value str">"rack.multiprocess"</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">false</span>, <span class="ruby-comment cmt"># ???</span>
|
||
|
52: <span class="ruby-value str">"rack.run_once"</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">false</span>,
|
||
|
53:
|
||
|
54: <span class="ruby-value str">"rack.url_scheme"</span> =<span class="ruby-operator">></span> <span class="ruby-value str">"http"</span>,
|
||
|
55: })
|
||
|
56: <span class="ruby-identifier">env</span>[<span class="ruby-value str">"QUERY_STRING"</span>] <span class="ruby-operator">||=</span> <span class="ruby-value str">""</span>
|
||
|
57: <span class="ruby-identifier">env</span>.<span class="ruby-identifier">delete</span> <span class="ruby-value str">"PATH_INFO"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">env</span>[<span class="ruby-value str">"PATH_INFO"</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">""</span>
|
||
|
58:
|
||
|
59: <span class="ruby-identifier">status</span>, <span class="ruby-identifier">headers</span>, <span class="ruby-identifier">body</span> = <span class="ruby-ivar">@app</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">env</span>)
|
||
|
60:
|
||
|
61: <span class="ruby-keyword kw">begin</span>
|
||
|
62: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">status</span>.<span class="ruby-identifier">to_i</span>
|
||
|
63: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">send_status</span>(<span class="ruby-keyword kw">nil</span>)
|
||
|
64:
|
||
|
65: <span class="ruby-identifier">headers</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>, <span class="ruby-identifier">vs</span><span class="ruby-operator">|</span>
|
||
|
66: <span class="ruby-identifier">vs</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
|
||
|
67: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">header</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
|
||
|
68: }
|
||
|
69: }
|
||
|
70: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">send_header</span>
|
||
|
71:
|
||
|
72: <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>
|
||
|
73: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">part</span>
|
||
|
74: <span class="ruby-identifier">response</span>.<span class="ruby-identifier">socket</span>.<span class="ruby-identifier">flush</span>
|
||
|
75: }
|
||
|
76: <span class="ruby-keyword kw">ensure</span>
|
||
|
77: <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>
|
||
|
78: <span class="ruby-keyword kw">end</span>
|
||
|
79: <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>
|