%PDF- %PDF-
Direktori : /opt/cpanel/ea-ruby27/root/usr/share/gems/doc/rack-2.2.10/rdoc/Rack/ |
Current File : //opt/cpanel/ea-ruby27/root/usr/share/gems/doc/rack-2.2.10/rdoc/Rack/Handler.html |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>module Rack::Handler - rack-2.2.10 Documentation</title> <script type="text/javascript"> var rdoc_rel_prefix = "../"; var index_rel_prefix = "../"; </script> <script src="../js/navigation.js" defer></script> <script src="../js/search.js" defer></script> <script src="../js/search_index.js" defer></script> <script src="../js/searcher.js" defer></script> <script src="../js/darkfish.js" defer></script> <link href="../css/fonts.css" rel="stylesheet"> <link href="../css/rdoc.css" rel="stylesheet"> <body id="top" role="document" class="module"> <nav role="navigation"> <div id="project-navigation"> <div id="home-section" role="region" title="Quick navigation" class="nav-section"> <h2> <a href="../index.html" rel="home">Home</a> </h2> <div id="table-of-contents-navigation"> <a href="../table_of_contents.html#pages">Pages</a> <a href="../table_of_contents.html#classes">Classes</a> <a href="../table_of_contents.html#methods">Methods</a> </div> </div> <div id="search-section" role="search" class="project-section initially-hidden"> <form action="#" method="get" accept-charset="utf-8"> <div id="search-field-wrapper"> <input id="search-field" role="combobox" aria-label="Search" aria-autocomplete="list" aria-controls="search-results" type="text" name="search" placeholder="Search" spellcheck="false" title="Type to search, Up and Down to navigate, Enter to load"> </div> <ul id="search-results" aria-label="Search Results" aria-busy="false" aria-expanded="false" aria-atomic="false" class="initially-hidden"></ul> </form> </div> </div> <div id="class-metadata"> <!-- Method Quickref --> <div id="method-list-section" class="nav-section"> <h3>Methods</h3> <ul class="link-list" role="directory"> <li ><a href="#method-c-default">::default</a> <li ><a href="#method-c-get">::get</a> <li ><a href="#method-c-pick">::pick</a> <li ><a href="#method-c-register">::register</a> <li ><a href="#method-c-try_require">::try_require</a> </ul> </div> </div> </nav> <main role="main" aria-labelledby="module-Rack::Handler"> <h1 id="module-Rack::Handler" class="module"> module Rack::Handler </h1> <section class="description"> <p><strong>Handlers</strong> connect web servers with <a href="../Rack.html"><code>Rack</code></a>.</p> <p><a href="../Rack.html"><code>Rack</code></a> includes Handlers for <a href="Handler/Thin.html"><code>Thin</code></a>, <a href="Handler/WEBrick.html"><code>WEBrick</code></a>, <a href="Handler/FastCGI.html"><code>FastCGI</code></a>, <a href="Handler/CGI.html"><code>CGI</code></a>, <a href="Handler/SCGI.html"><code>SCGI</code></a> and LiteSpeed.</p> <p>Handlers usually are activated by calling <code>MyHandler.run(myapp)</code>. A second optional hash can be passed to include server-specific configuration.</p> </section> <section id="5Buntitled-5D" class="documentation-section"> <section class="constants-list"> <header> <h3>Constants</h3> </header> <dl> <dt id="SERVER_NAMES">SERVER_NAMES <dd> </dl> </section> <section id="public-class-5Buntitled-5D-method-details" class="method-section"> <header> <h3>Public Class Methods</h3> </header> <div id="method-c-default" class="method-detail "> <div class="method-heading"> <span class="method-name">default</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="default-source"> <pre><span class="ruby-comment"># File lib/rack/handler.rb, line 51</span> <span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">default</span> <span class="ruby-comment"># Guess.</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">ENV</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-string">"PHP_FCGI_CHILDREN"</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">FastCGI</span> <span class="ruby-keyword">elsif</span> <span class="ruby-constant">ENV</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-constant">REQUEST_METHOD</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">CGI</span> <span class="ruby-keyword">elsif</span> <span class="ruby-constant">ENV</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-string">"RACK_HANDLER"</span>) <span class="ruby-keyword">self</span>.<span class="ruby-identifier">get</span>(<span class="ruby-constant">ENV</span>[<span class="ruby-string">"RACK_HANDLER"</span>]) <span class="ruby-keyword">else</span> <span class="ruby-identifier">pick</span> <span class="ruby-constant">SERVER_NAMES</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">end</span></pre> </div> </div> </div> <div id="method-c-get" class="method-detail "> <div class="method-heading"> <span class="method-name">get</span><span class="method-args">(server)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="get-source"> <pre><span class="ruby-comment"># File lib/rack/handler.rb, line 13</span> <span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">get</span>(<span class="ruby-identifier">server</span>) <span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">server</span> <span class="ruby-identifier">server</span> = <span class="ruby-identifier">server</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@handlers</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">server</span> <span class="ruby-identifier">load_error</span> = <span class="ruby-identifier">try_require</span>(<span class="ruby-string">'rack/handler'</span>, <span class="ruby-identifier">server</span>) <span class="ruby-keyword">end</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">klass</span> = <span class="ruby-ivar">@handlers</span>[<span class="ruby-identifier">server</span>] <span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">klass</span>) <span class="ruby-keyword">else</span> <span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">server</span>, <span class="ruby-keyword">false</span>) <span class="ruby-keyword">end</span> <span class="ruby-keyword">rescue</span> <span class="ruby-constant">NameError</span> <span class="ruby-operator">=></span> <span class="ruby-identifier">name_error</span> <span class="ruby-identifier">raise</span> <span class="ruby-identifier">load_error</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">name_error</span> <span class="ruby-keyword">end</span></pre> </div> </div> </div> <div id="method-c-pick" class="method-detail "> <div class="method-heading"> <span class="method-name">pick</span><span class="method-args">(server_names)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <p>Select first available <a href="../Rack.html"><code>Rack</code></a> handler given an `Array` of server names. Raises `LoadError` if no handler was found.</p> <pre>> pick ['thin', 'webrick'] => Rack::Handler::WEBrick</pre> <div class="method-source-code" id="pick-source"> <pre><span class="ruby-comment"># File lib/rack/handler.rb, line 36</span> <span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">pick</span>(<span class="ruby-identifier">server_names</span>) <span class="ruby-identifier">server_names</span> = <span class="ruby-constant">Array</span>(<span class="ruby-identifier">server_names</span>) <span class="ruby-identifier">server_names</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">server_name</span><span class="ruby-operator">|</span> <span class="ruby-keyword">begin</span> <span class="ruby-keyword">return</span> <span class="ruby-identifier">get</span>(<span class="ruby-identifier">server_name</span>.<span class="ruby-identifier">to_s</span>) <span class="ruby-keyword">rescue</span> <span class="ruby-constant">LoadError</span>, <span class="ruby-constant">NameError</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">end</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">LoadError</span>, <span class="ruby-node">"Couldn't find handler for: #{server_names.join(', ')}."</span> <span class="ruby-keyword">end</span></pre> </div> </div> </div> <div id="method-c-register" class="method-detail "> <div class="method-heading"> <span class="method-name">register</span><span class="method-args">(server, klass)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="register-source"> <pre><span class="ruby-comment"># File lib/rack/handler.rb, line 85</span> <span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">register</span>(<span class="ruby-identifier">server</span>, <span class="ruby-identifier">klass</span>) <span class="ruby-ivar">@handlers</span> <span class="ruby-operator">||=</span> {} <span class="ruby-ivar">@handlers</span>[<span class="ruby-identifier">server</span>.<span class="ruby-identifier">to_s</span>] = <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-keyword">end</span></pre> </div> </div> </div> <div id="method-c-try_require" class="method-detail "> <div class="method-heading"> <span class="method-name">try_require</span><span class="method-args">(prefix, const_name)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <p>Transforms server-name constants to their canonical form as filenames, then tries to require them but silences the LoadError if not found</p> <p>Naming convention:</p> <pre class="ruby"><span class="ruby-constant">Foo</span> <span class="ruby-comment"># => 'foo'</span> <span class="ruby-constant">FooBar</span> <span class="ruby-comment"># => 'foo_bar.rb'</span> <span class="ruby-constant">FooBAR</span> <span class="ruby-comment"># => 'foobar.rb'</span> <span class="ruby-constant">FOObar</span> <span class="ruby-comment"># => 'foobar.rb'</span> <span class="ruby-constant">FOOBAR</span> <span class="ruby-comment"># => 'foobar.rb'</span> <span class="ruby-constant">FooBarBaz</span> <span class="ruby-comment"># => 'foo_bar_baz.rb'</span> </pre> <div class="method-source-code" id="try_require-source"> <pre><span class="ruby-comment"># File lib/rack/handler.rb, line 75</span> <span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">try_require</span>(<span class="ruby-identifier">prefix</span>, <span class="ruby-identifier">const_name</span>) <span class="ruby-identifier">file</span> = <span class="ruby-identifier">const_name</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp">/^[A-Z]+/</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">pre</span><span class="ruby-operator">|</span> <span class="ruby-identifier">pre</span>.<span class="ruby-identifier">downcase</span> }. <span class="ruby-identifier">gsub</span>(<span class="ruby-regexp">/[A-Z]+[^A-Z]/</span>, <span class="ruby-string">'_\&'</span>).<span class="ruby-identifier">downcase</span> <span class="ruby-identifier">require</span>(<span class="ruby-operator">::</span><span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">prefix</span>, <span class="ruby-identifier">file</span>)) <span class="ruby-keyword">nil</span> <span class="ruby-keyword">rescue</span> <span class="ruby-constant">LoadError</span> <span class="ruby-operator">=></span> <span class="ruby-identifier">error</span> <span class="ruby-identifier">error</span> <span class="ruby-keyword">end</span></pre> </div> </div> </div> </section> </section> </main> <footer id="validator-badges" role="contentinfo"> <p><a href="https://validator.w3.org/check/referer">Validate</a> <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.2.1.1. <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>. </footer>