Browse files

update purpose of middleware

  • Loading branch information...
shime committed Apr 2, 2012
1 parent b95aa05 commit 4b1ed1d29f9d42f6d52562778f35c3b0e2888b72
Showing with 66 additions and 11 deletions.
  1. +66 −11 guides/source/rails_on_rack.textile
@@ -164,18 +164,73 @@ config.middleware.delete(middleware)
h4. Internal Middleware Stack
Much of Action Controller's functionality is implemented as Middlewares. The following table explains the purpose of each of them:
Much of Action Controller's functionality is implemented as Middlewares. The following list explains the purpose of each of them:
|+Rack::Lock+|Sets <tt>env["rack.multithread"]</tt> 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+|Enables the Active Record query cache.|
|+ActionDispatch::Session::CookieStore+|Uses the cookie based session store.|
|+ActionDispatch::Session::CacheStore+|Uses the Rails cache based session store.|
|+ActionDispatch::Session::MemCacheStore+|Uses the memcached based session store.|
|+ActiveRecord::SessionStore+|Uses the database based session store.|
|+Rack::MethodOverride+|Sets HTTP method based on +_method+ parameter or <tt>env["HTTP_X_HTTP_METHOD_OVERRIDE"]</tt>.|
|+Rack::Head+|Discards the response body if the client sends a +HEAD+ request.|
* Used to serve static assets. Disabled if <tt>config.serve_static_assets</tt> is true.
* Sets <tt>env["rack.multithread"]</tt> flag to +true+ and wraps the application within a Mutex.
* Used for memory caching. This cache is not thread safe.
* Sets an X-Runtime header, containing the time (in seconds) taken to execute the request.
* Allows the method to be overridden if <tt>params[:_method]</tt> is set. This is the middleware which supports the PUT and DELETE HTTP method types.
* Makes a unique +X-Request-Id+ header available to the response and enables the <tt>ActionDispatch::Request#uuid</tt> method.
* Notifies the logs that the request has began. After request is complete, flushes all the logs.
* Rescues any exception returned by the application and calls an exceptions app that will wrap it in a format for the end user.
* Responsible for logging exceptions and showing a debugging page in case the request is local.
* Checks for IP spoofing attacks.
* Provides prepare and cleanup callbacks, intended to assist with code reloading during development.
* Runs the prepare callbacks before serving the request.
* Cleans active connections after each request, unless the <tt>rack.test</tt> key in the request environment is set to +true+.
* Enables the Active Record query cache.
* Sets cookies for the request.
* Responsible for storing the session in cookies.
* Sets up the flash keys. Only available if <tt>config.action_controller.session_store</tt> is set to a value.
* Parses out parameters from the request into <tt>params</tt>.
* Converts HEAD requests to +GET+ requests and serves them as so.
* Adds support for "Conditional +GET+" so that server responds with nothing if page wasn't changed.
* Adds ETag header on all String bodies. ETags are used to validate cache.
* Enables “best standards support” so that IE8 renders some elements correctly.
TIP: It's possible to use any of the above middlewares in your custom Rack stack.

0 comments on commit 4b1ed1d

Please sign in to comment.