Updated README.rdoc again
[feedcatcher.git] / vendor / rails / actionpack / lib / action_controller / vendor / rack-1.0 / rack / static.rb
1 module Rack
2
3 # The Rack::Static middleware intercepts requests for static files
4 # (javascript files, images, stylesheets, etc) based on the url prefixes
5 # passed in the options, and serves them using a Rack::File object. This
6 # allows a Rack stack to serve both static and dynamic content.
7 #
8 # Examples:
9 # use Rack::Static, :urls => ["/media"]
10 # will serve all requests beginning with /media from the "media" folder
11 # located in the current directory (ie media/*).
12 #
13 # use Rack::Static, :urls => ["/css", "/images"], :root => "public"
14 # will serve all requests beginning with /css or /images from the folder
15 # "public" in the current directory (ie public/css/* and public/images/*)
16
17 class Static
18
19 def initialize(app, options={})
20 @app = app
21 @urls = options[:urls] || ["/favicon.ico"]
22 root = options[:root] || Dir.pwd
23 @file_server = Rack::File.new(root)
24 end
25
26 def call(env)
27 path = env["PATH_INFO"]
28 can_serve = @urls.any? { |url| path.index(url) == 0 }
29
30 if can_serve
31 @file_server.call(env)
32 else
33 @app.call(env)
34 end
35 end
36
37 end
38 end