mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Update internal middlewares/purpose table.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -241,11 +241,11 @@ and unobtrusive JavaScript. His home on the internet is his blog <a href="http:/
|
||||
<div class="sidebar-title">Cássio Marques</div>
|
||||
<div class="paragraph"><p>Cássio Marques is a Brazilian software developer working with different programming languages such as Ruby, JavaScript, C++ and Java, as an independent consultant. He blogs at <a href="http://cassiomarques.wordpress.com">http://cassiomarques.wordpress.com</a>, which is mainly written in portuguese, but will soon get a new section for posts with english translation.</p></div>
|
||||
</div></div>
|
||||
<div class="sidebarblock" id="lifo">
|
||||
<div class="sidebar-content">
|
||||
<div class="sidebar-title">Pratik Naik</div>
|
||||
<div class="paragraph"><p>Pratik Naik is an independent Ruby on Rails consultant and also a member of the <a href="http://rubyonrails.com/core">Rails core team</a>. He blogs semi-regularly at <a href="http://m.onkey.org">has_many :bugs, :through => :rails</a> and has an active <a href="http://twitter.com/lifo">twitter account</a> .</p></div>
|
||||
</div></div>
|
||||
<div class="sidebarblock" id="lifo">
|
||||
<div class="sidebar-content">
|
||||
<div class="sidebar-title">Pratik Naik</div>
|
||||
<div class="paragraph"><p>Pratik Naik is an independent Ruby on Rails consultant and also a member of the <a href="http://rubyonrails.com/core">Rails core team</a>. He blogs semi-regularly at <a href="http://m.onkey.org">has_many :bugs, :through => :rails</a> and has an active <a href="http://twitter.com/lifo">twitter account</a> .</p></div>
|
||||
</div></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -260,7 +260,7 @@ ul#navMain {
|
||||
</div></div>
|
||||
<div class="sidebarblock">
|
||||
<div class="sidebar-content">
|
||||
<div class="sidebar-title"><a href="active_record_querying.html">Active Record Query Interface</a></div>
|
||||
<div class="sidebar-title"><a href="active_record_querying.html">Active Record Query Interface</a></div>
|
||||
<div class="admonitionblock">
|
||||
<table><tr>
|
||||
<td class="icon">
|
||||
@@ -269,7 +269,7 @@ ul#navMain {
|
||||
<td class="content"><a href="http://rails.lighthouseapp.com/projects/16213/tickets/16">Lighthouse Ticket</a></td>
|
||||
</tr></table>
|
||||
</div>
|
||||
<div class="paragraph"><p>This guide covers the database query interface provided by Active Record.</p></div>
|
||||
<div class="paragraph"><p>This guide covers the database query interface provided by Active Record.</p></div>
|
||||
</div></div>
|
||||
<h2>Views</h2>
|
||||
<div class="sidebarblock">
|
||||
@@ -349,7 +349,7 @@ of your code.</p></div>
|
||||
<div class="sidebarblock">
|
||||
<div class="sidebar-content">
|
||||
<div class="sidebar-title"><a href="performance_testing.html">Performance Testing Rails Applications</a></div>
|
||||
<div class="paragraph"><p>This guide covers ways to benchmark and profile your Rails application.</p></div>
|
||||
<div class="paragraph"><p>This guide covers ways to benchmark and profile your Rails application.</p></div>
|
||||
</div></div>
|
||||
<div class="sidebarblock">
|
||||
<div class="sidebar-content">
|
||||
|
||||
@@ -574,7 +574,7 @@ http://www.gnu.org/software/src-highlite -->
|
||||
<pre><tt>ActionController<span style="color: #990000">::</span>Base<span style="color: #990000">.</span>perform_caching <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #0000FF">true</span></span>
|
||||
ActiveSupport<span style="color: #990000">::</span>Dependencies<span style="color: #990000">.</span>mechanism <span style="color: #990000">=</span> <span style="color: #990000">:</span>require
|
||||
Rails<span style="color: #990000">.</span>logger<span style="color: #990000">.</span>level <span style="color: #990000">=</span> ActiveSupport<span style="color: #990000">::</span>BufferedLogger<span style="color: #990000">::</span>INFO</tt></pre></div></div>
|
||||
<div class="paragraph"><p>As <tt>ActionController::Base.perform_caching</tt> is set to <tt>true</tt>, performance tests will behave much as they do in the <tt>production</tt> environment.</p></div>
|
||||
<div class="paragraph"><p>As <tt>ActionController::Base.perform_caching</tt> is set to <tt>true</tt>, performance tests will behave much as they do in the <tt>production</tt> environment.</p></div>
|
||||
<h3 id="gc">1.8. Installing GC-Patched Ruby</h3>
|
||||
<div class="paragraph"><p>To get the best from Rails performance tests, you need to build a special Ruby binary with some super powers - <a href="http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch">GC patch</a> for measuring GC Runs/Time and memory/object allocation.</p></div>
|
||||
<div class="paragraph"><p>The process is fairly straight forward. If you’ve never compiled a Ruby binary before, follow these steps to build a ruby binary inside your home directory:</p></div>
|
||||
@@ -879,7 +879,7 @@ http://www.gnu.org/software/src-highlite -->
|
||||
<div class="ulist"><ul>
|
||||
<li>
|
||||
<p>
|
||||
January 9, 2009: Complete rewrite by <a href="../authors.html#lifo">Pratik</a>
|
||||
January 9, 2009: Complete rewrite by <a href="../authors.html#lifo">Pratik</a>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
|
||||
@@ -233,6 +233,8 @@ ul#navMain {
|
||||
|
||||
<li><a href="#_generating_a_metal_application">Generating a Metal Application</a></li>
|
||||
|
||||
<li><a href="#_execution_order">Execution Order</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
@@ -465,31 +467,31 @@ cellspacing="0" cellpadding="4">
|
||||
<tbody valign="top">
|
||||
<tr>
|
||||
<td align="left"><p class="table">ActionController::Lock</p></td>
|
||||
<td align="left"><p class="table">Mutex</p></td>
|
||||
<td align="left"><p class="table">Sets <tt>env["rack.multithread"]</tt> flag to <tt>true</tt> and wraps the application within a Mutex.</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left"><p class="table">ActionController::Failsafe</p></td>
|
||||
<td align="left"><p class="table">Never fail</p></td>
|
||||
<td align="left"><p class="table">Returns HTTP Status <tt>500</tt> to the client if an exception gets raised while dispatching.</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left"><p class="table">ActiveRecord::QueryCache</p></td>
|
||||
<td align="left"><p class="table">Query caching</p></td>
|
||||
<td align="left"><p class="table">Enable the Active Record query cache.</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left"><p class="table">ActionController::Session::CookieStore</p></td>
|
||||
<td align="left"><p class="table">Query caching</p></td>
|
||||
<td align="left"><p class="table">Uses the cookie based session store.</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left"><p class="table">ActionController::Session::MemCacheStore</p></td>
|
||||
<td align="left"><p class="table">Query caching</p></td>
|
||||
<td align="left"><p class="table">Uses the memcached based session store.</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left"><p class="table">ActiveRecord::SessionStore</p></td>
|
||||
<td align="left"><p class="table">Query caching</p></td>
|
||||
<td align="left"><p class="table">Uses the database based session store.</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left"><p class="table">ActionController::VerbPiggybacking</p></td>
|
||||
<td align="left"><p class="table">_method hax</p></td>
|
||||
<td align="left"><p class="table">Sets HTTP method based on <tt>_method</tt> parameter or <tt>env["HTTP_X_HTTP_METHOD_OVERRIDE"]</tt>.</p></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -571,6 +573,30 @@ http://www.gnu.org/software/src-highlite -->
|
||||
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
||||
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
|
||||
<div class="paragraph"><p>Metal applications are an optimization. You should make sure to <a href="http://weblog.rubyonrails.org/2008/12/20/performance-of-rails-metal">understand the related performance implications</a> before using it.</p></div>
|
||||
<h3 id="_execution_order">4.2. Execution Order</h3>
|
||||
<div class="paragraph"><p>All Metal Applications are executed by <tt>Rails::Rack::Metal</tt> middleware, which is a part of the <tt>ActionController::MiddlewareStack</tt> chain.</p></div>
|
||||
<div class="paragraph"><p>Here’s the primary method responsible for running the Metal applications:</p></div>
|
||||
<div class="listingblock">
|
||||
<div class="content"><!-- Generator: GNU source-highlight 2.9
|
||||
by Lorenzo Bettini
|
||||
http://www.lorenzobettini.it
|
||||
http://www.gnu.org/software/src-highlite -->
|
||||
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">def</span></span> call<span style="color: #990000">(</span>env<span style="color: #990000">)</span>
|
||||
<span style="color: #009900">@metals</span><span style="color: #990000">.</span>keys<span style="color: #990000">.</span>each <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>app<span style="color: #990000">|</span>
|
||||
result <span style="color: #990000">=</span> app<span style="color: #990000">.</span>call<span style="color: #990000">(</span>env<span style="color: #990000">)</span>
|
||||
<span style="font-weight: bold"><span style="color: #0000FF">return</span></span> result <span style="font-weight: bold"><span style="color: #0000FF">unless</span></span> result<span style="color: #990000">[</span><span style="color: #993399">0</span><span style="color: #990000">].</span>to_i <span style="color: #990000">==</span> <span style="color: #993399">404</span>
|
||||
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
|
||||
<span style="color: #009900">@app</span><span style="color: #990000">.</span>call<span style="color: #990000">(</span>env<span style="color: #990000">)</span>
|
||||
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
|
||||
<div class="paragraph"><p>In the code above, <tt>@metals</tt> is an ordered ( alphabetical ) hash of metal applications. Due to the alphabetical ordering, <tt>aaa.rb</tt> will come before <tt>bbb.rb</tt> in the metal chain.</p></div>
|
||||
<div class="admonitionblock">
|
||||
<table><tr>
|
||||
<td class="icon">
|
||||
<img src="./images/icons/important.png" alt="Important" />
|
||||
</td>
|
||||
<td class="content">Metal applications cannot return the HTTP Status <tt>404</tt> to a client, as it is used for continuing the Metal chain execution. Please use normal Rails controllers or a custom middleware if returning <tt>404</tt> is a requirement.</td>
|
||||
</tr></table>
|
||||
</div>
|
||||
</div>
|
||||
<h2 id="_middlewares_and_rails">5. Middlewares and Rails</h2>
|
||||
<div class="sectionbody">
|
||||
@@ -581,7 +607,7 @@ http://www.gnu.org/software/src-highlite -->
|
||||
<div class="ulist"><ul>
|
||||
<li>
|
||||
<p>
|
||||
January 11, 2009: First version by <a href="../authors.html#lifo">Pratik</a>
|
||||
January 11, 2009: First version by <a href="../authors.html#lifo">Pratik</a>
|
||||
</p>
|
||||
</li>
|
||||
</ul></div>
|
||||
|
||||
@@ -136,13 +136,13 @@ use ActionController::VerbPiggybacking
|
||||
[options="header"]
|
||||
|==========================================================================================================
|
||||
|Middleware |Purpose
|
||||
|ActionController::Lock | Mutex
|
||||
|ActionController::Failsafe | Never fail
|
||||
|ActiveRecord::QueryCache | Query caching
|
||||
|ActionController::Session::CookieStore | Query caching
|
||||
|ActionController::Session::MemCacheStore | Query caching
|
||||
|ActiveRecord::SessionStore | Query caching
|
||||
|ActionController::VerbPiggybacking | _method hax
|
||||
|ActionController::Lock | Sets +env["rack.multithread"]+ flag to +true+ and wraps the application within a Mutex.
|
||||
|ActionController::Failsafe | Returns HTTP Status +500+ to the client if an exception gets raised while dispatching.
|
||||
|ActiveRecord::QueryCache | Enable the Active Record query cache.
|
||||
|ActionController::Session::CookieStore | Uses the cookie based session store.
|
||||
|ActionController::Session::MemCacheStore | Uses the memcached based session store.
|
||||
|ActiveRecord::SessionStore | Uses the database based session store.
|
||||
|ActionController::VerbPiggybacking | Sets HTTP method based on +_method+ parameter or +env["HTTP_X_HTTP_METHOD_OVERRIDE"]+.
|
||||
|==========================================================================================================
|
||||
|
||||
=== Customizing Internal Middleware Stack ===
|
||||
@@ -228,10 +228,29 @@ end
|
||||
|
||||
Metal applications are an optimization. You should make sure to http://weblog.rubyonrails.org/2008/12/20/performance-of-rails-metal[understand the related performance implications] before using it.
|
||||
|
||||
=== Execution Order ===
|
||||
|
||||
All Metal Applications are executed by +Rails::Rack::Metal+ middleware, which is a part of the +ActionController::MiddlewareStack+ chain.
|
||||
|
||||
Here's the primary method responsible for running the Metal applications:
|
||||
|
||||
[source, ruby]
|
||||
----------------------------------------------------------------------------
|
||||
def call(env)
|
||||
@metals.keys.each do |app|
|
||||
result = app.call(env)
|
||||
return result unless result[0].to_i == 404
|
||||
end
|
||||
@app.call(env)
|
||||
end
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
In the code above, +@metals+ is an ordered ( alphabetical ) hash of metal applications. Due to the alphabetical ordering, +aaa.rb+ will come before +bbb.rb+ in the metal chain.
|
||||
|
||||
IMPORTANT: Metal applications cannot return the HTTP Status +404+ to a client, as it is used for continuing the Metal chain execution. Please use normal Rails controllers or a custom middleware if returning +404+ is a requirement.
|
||||
|
||||
== Middlewares and Rails ==
|
||||
|
||||
|
||||
|
||||
== Changelog ==
|
||||
|
||||
http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/4[Lighthouse ticket]
|
||||
|
||||
Reference in New Issue
Block a user