diff --git a/README.rdoc b/README.rdoc index f1dc1013..d21cca3f 100644 --- a/README.rdoc +++ b/README.rdoc @@ -349,6 +349,30 @@ When using send_file or static files you may have mime types Sinatra doesn't und mime :foo, 'text/foo' += Using Rack Middleware + +Sinatra rides on Rack[http://rack.rubyforge.org/], a minimal standard interface for Ruby web frameworks. One of Rack's most interesting capabilities for application developers is support for "middleware" -- components that sit between the server and your application monitoring and/or manipulating the HTTP request/response to provide various types of common functionality. What's more, middleware is portable between web frameworks, so middleware components developed under, e.g., Merb, can be used with Sinatra and vice versa. + +Sinatra makes building Rack middleware pipelines a cinch via a top-level +use+ method: + + require 'sinatra' + require 'my_custom_middleware' + + use Rack::Lint + use MyCustomMiddleware + + get '/hello' do + 'Hello World' + end + +The semantics of +use+ are identical to those defined for the Rack::Builder[http://rack.rubyforge.org/doc/classes/Rack/Builder.html] DSL (most frequently used from rackup files). For example, the +use+ method accepts multiple/variable args as well as blocks: + + use Rack::Auth::Basic do |username, password| + username == 'admin' && password == 'secret' + end + +Rack is distributed with a variety of standard middleware for logging, debugging, URL routing, authentication, and session handling. Sinatra uses many of of these components automatically based on configuration so you typically don't have to +use+ them explicitly. + = Testing === Methods diff --git a/lib/sinatra.rb b/lib/sinatra.rb index 439a8f43..f3544823 100644 --- a/lib/sinatra.rb +++ b/lib/sinatra.rb @@ -485,8 +485,8 @@ module Sinatra # database queries, template rendering, complex logic) can dramatically # increase overall throughput with caching clients. # - # === See Also - # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.19[RFC2616: ETag], + # ==== See Also + # {RFC2616: ETag}[http://w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.19], # ResponseHelpers#last_modified def entity_tag(value, strength=:strong) value = @@ -902,6 +902,7 @@ module Sinatra :public => root + '/public', :sessions => false, :logging => true, + :app_file => $0, :raise_errors => false } load_default_options_from_command_line! @@ -1087,8 +1088,8 @@ module Sinatra error NotFound, options, &b end - # Define a request filter. When +type+ is +:before+, execute the block - # in the context of each request before matching event handlers. + # Define a request filter. When type is :before, execute the + # block in the context of each request before matching event handlers. def filter(type, &b) filters[type] << b end @@ -1111,7 +1112,7 @@ module Sinatra load_default_configuration! @pipeline = nil @reloading = true - Kernel.load $0 + Kernel.load Sinatra.options.app_file @reloading = false end