237 lines
13 KiB
HTML
237 lines
13 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::WEBrick</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::WEBrick</td>
|
||
|
</tr>
|
||
|
<tr class="top-aligned-row">
|
||
|
<td><strong>In:</strong></td>
|
||
|
<td>
|
||
|
<a href="../../../files/lib/rack/handler/webrick_rb.html">
|
||
|
lib/rack/handler/webrick.rb
|
||
|
</a>
|
||
|
<br />
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr class="top-aligned-row">
|
||
|
<td><strong>Parent:</strong></td>
|
||
|
<td>
|
||
|
::WEBrick::HTTPServlet::AbstractServlet
|
||
|
</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="#M000063">new</a>
|
||
|
<a href="#M000062">run</a>
|
||
|
<a href="#M000064">service</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-M000063" class="method-detail">
|
||
|
<a name="M000063"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000063" class="method-signature">
|
||
|
<span class="method-name">new</span><span class="method-args">(server, app)</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000063-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000063-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/handler/webrick.rb, line 15</span>
|
||
|
15: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">server</span>, <span class="ruby-identifier">app</span>)
|
||
|
16: <span class="ruby-keyword kw">super</span> <span class="ruby-identifier">server</span>
|
||
|
17: <span class="ruby-ivar">@app</span> = <span class="ruby-identifier">app</span>
|
||
|
18: <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div id="method-M000062" class="method-detail">
|
||
|
<a name="M000062"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000062" 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('M000062-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000062-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/handler/webrick.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">WEBrick</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPServer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">options</span>)
|
||
|
9: <span class="ruby-identifier">server</span>.<span class="ruby-identifier">mount</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">WEBrick</span>, <span class="ruby-identifier">app</span>
|
||
|
10: <span class="ruby-identifier">trap</span>(<span class="ruby-identifier">:INT</span>) { <span class="ruby-identifier">server</span>.<span class="ruby-identifier">shutdown</span> }
|
||
|
11: <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>
|
||
|
12: <span class="ruby-identifier">server</span>.<span class="ruby-identifier">start</span>
|
||
|
13: <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<h3 class="section-bar">Public Instance methods</h3>
|
||
|
|
||
|
<div id="method-M000064" class="method-detail">
|
||
|
<a name="M000064"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000064" class="method-signature">
|
||
|
<span class="method-name">service</span><span class="method-args">(req, res)</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000064-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000064-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/handler/webrick.rb, line 20</span>
|
||
|
20: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">service</span>(<span class="ruby-identifier">req</span>, <span class="ruby-identifier">res</span>)
|
||
|
21: <span class="ruby-identifier">env</span> = <span class="ruby-identifier">req</span>.<span class="ruby-identifier">meta_vars</span>
|
||
|
22: <span class="ruby-identifier">env</span>.<span class="ruby-identifier">delete_if</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">nil?</span> }
|
||
|
23:
|
||
|
24: <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>],
|
||
|
25: <span class="ruby-value str">"rack.input"</span> =<span class="ruby-operator">></span> <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">req</span>.<span class="ruby-identifier">body</span>.<span class="ruby-identifier">to_s</span>),
|
||
|
26: <span class="ruby-value str">"rack.errors"</span> =<span class="ruby-operator">></span> <span class="ruby-constant">STDERR</span>,
|
||
|
27:
|
||
|
28: <span class="ruby-value str">"rack.multithread"</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">true</span>,
|
||
|
29: <span class="ruby-value str">"rack.multiprocess"</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">false</span>,
|
||
|
30: <span class="ruby-value str">"rack.run_once"</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">false</span>,
|
||
|
31:
|
||
|
32: <span class="ruby-value str">"rack.url_scheme"</span> =<span class="ruby-operator">></span> [<span class="ruby-value str">"yes"</span>, <span class="ruby-value str">"on"</span>, <span class="ruby-value str">"1"</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-constant">ENV</span>[<span class="ruby-value str">"HTTPS"</span>]) <span class="ruby-operator">?</span> <span class="ruby-value str">"https"</span> <span class="ruby-operator">:</span> <span class="ruby-value str">"http"</span>
|
||
|
33: })
|
||
|
34:
|
||
|
35: <span class="ruby-identifier">env</span>[<span class="ruby-value str">"HTTP_VERSION"</span>] <span class="ruby-operator">||=</span> <span class="ruby-identifier">env</span>[<span class="ruby-value str">"SERVER_PROTOCOL"</span>]
|
||
|
36: <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>
|
||
|
37: <span class="ruby-identifier">env</span>[<span class="ruby-value str">"REQUEST_PATH"</span>] <span class="ruby-operator">||=</span> <span class="ruby-value str">"/"</span>
|
||
|
38: <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>
|
||
|
39:
|
||
|
40: <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>)
|
||
|
41: <span class="ruby-keyword kw">begin</span>
|
||
|
42: <span class="ruby-identifier">res</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">status</span>.<span class="ruby-identifier">to_i</span>
|
||
|
43: <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>
|
||
|
44: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">k</span>.<span class="ruby-identifier">downcase</span> <span class="ruby-operator">==</span> <span class="ruby-value str">"set-cookie"</span>
|
||
|
45: <span class="ruby-identifier">res</span>.<span class="ruby-identifier">cookies</span>.<span class="ruby-identifier">concat</span> <span class="ruby-identifier">vs</span>.<span class="ruby-identifier">to_a</span>
|
||
|
46: <span class="ruby-keyword kw">else</span>
|
||
|
47: <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>
|
||
|
48: <span class="ruby-identifier">res</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
|
||
|
49: }
|
||
|
50: <span class="ruby-keyword kw">end</span>
|
||
|
51: }
|
||
|
52: <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>
|
||
|
53: <span class="ruby-identifier">res</span>.<span class="ruby-identifier">body</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">part</span>
|
||
|
54: }
|
||
|
55: <span class="ruby-keyword kw">ensure</span>
|
||
|
56: <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>
|
||
|
57: <span class="ruby-keyword kw">end</span>
|
||
|
58: <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>
|