Rack Middlewares

botanicus edited this page Sep 13, 2010 · 18 revisions

This page is up to date for Rango 0.1.

Rango middlewares

All Rango middlewares are located in lib/rango/rack/middlewares.

  • Rango::Basic is the basic and most important Rango middleware. It should be used in all Rango applications. It set up serving of static files, cookies, content length, content type and rewritting to proper HTTP method if params includes _method key.
  • Rango::Static can serve static files even if they haven’t specific URL prefix. This middleware is automatically used by Rango::Basic.
  • Rango::Encoding forces your default encoding for Rack env. This middleware is automatically used by Rango::Basic.
  • Rango::EmailObfuscator for all text/html documents replaces all @ in <body> by it’s entity, to prevent spam robots to find your email. It’s easy, but surprisingly powerful technique.

Middlewares included in Rack

  • Rack::Head Drop the body of the response on HEAD requests.
  • Rack::Deflater – gzip your responses.
  • Rack::ConditionalGet – enables conditional GET using If-None-Match and If-Modified-Since.
  • Rack::Session::Cookie and Rack::Session::Memcache – provide session management.
  • Rack::Auth::Basic – implements HTTP Basic Authentication.
  • Rack::URLMap is simple router useful for applications with very simple routing rulez, webservices etc. See section routers.
  • Rack::Static
  • Rack::ShowStatus
  • Rack::ShowExceptions
  • Rack::Reloader
  • Rack::Recursive
  • Rack::MethodOverride Override REQUEST_METHOD with _method post params for HTML forms.
  • Rack::Lock
  • Rack::Lobster
  • Rack::Lint
  • Rack::Head
  • Rack::File
  • Rack::Directory
  • Rack::Deflater
  • Rack::ContentType
  • Rack::ContentLength
  • Rack::ConditionalGet
  • Rack::CommonLogger
  • Rack::Chunked
  • Rack::Auth::Basic
  • Rack::Auth::Digest::MD5
  • Rack::Auth::OpenID
  • Rack::Session::Cookie

Rack contrib project

(The description bellow was stolen from README in rack-contrib)

  • Rack::ETag – Automatically sets the ETag header on all String bodies.
  • Rack::JSONP – Adds JSON-P support by stripping out the callback param and padding the response with the appropriate callback format.
  • Rack::LighttpdScriptNameFix – Fixes how lighttpd sets the SCRIPT_NAME and PATH_INFO variables in certain configurations.
  • Rack::Locale – Detects the client locale using the Accept-Language request header and sets a rack.locale variable in the environment.
  • Rack::MailExceptions – Rescues exceptions raised from the app and sends a useful email with the exception, stacktrace, and contents of the environment.
  • Rack::NestedParams – parses form params with subscripts (e.g., * “post[title]=Hello”) into a nested/recursive Hash structure (based on Rails’ implementation).
  • Rack::PostBodyContentTypeParser – Adds support for JSON request bodies. The Rack parameter hash is populated by deserializing the JSON data provided in the request body when the Content-Type is application/json.
  • Rack::ProcTitle – Displays request information in process title ($0) for monitoring/inspection with ps(1).
  • Rack::Profiler – Uses ruby-prof to measure request time.
  • Rack::Sendfile – Enables X-Sendfile support for bodies that can be served from file.
  • Rack::Signals – Installs signal handlers that are safely processed after a request
  • Rack::StaticCache – Modifies the response headers to facilitiate client and proxy caching for static files that minimizes http requests and improves overall load times for second time visitors.
  • Rack::TimeZone – Detects the clients timezone using JavaScript and sets a variable in Rack’s environment with the offset from UTC.
  • Rack::Evil – Lets the rack application return a response to the client from any place.
  • Rack::Callbacks – Implements DLS for pure before/after filter like Middlewares.
  • Rack::Config – Shared configuration for cooperative middleware.
  • Rack::NotFound – A default 404 application.
  • Rack::CSSHTTPRequest – Adds CSSHTTPRequest support by encoding responses as CSS for cross-site AJAX-style data loading
  • Rack::Deflect – Helps protect against DoS attacks.
  • Rack::ResponseCache – Caches responses to requests without query strings to Disk or a user provider Ruby object. Similar to Rails’ page caching.
  • Rack::RelativeRedirect – Transforms relative paths in redirects to absolute URLs.
  • Rack::Backstage – Returns content of specified file if it exists, which makes it convenient for putting up maintenance pages.
  • Rack::AcceptFormat – Adds a format extension at the end of the URI when there is none, corresponding to the mime-type given in the Accept HTTP header.
  • Rack::HostMeta – Configures /host-meta using a block
  • Rack::Cookies – Adds simple cookie jar hash to env


“http://blog.tie-rack.org/2009/3/27/Using-Rack-Middleware-to-Modify-the-Request-Environment.html”: Detect mobile device