summary refs log tree commit
path: root/lib/rack/file.rb
diff options
context:
space:
mode:
authorThomas Klemm <github@tklemm.eu>2012-08-17 12:31:11 +0200
committerThomas Klemm <github@tklemm.eu>2012-08-17 13:30:25 +0200
commitbeddb2a46626515690d9d2ea02b30904e8a346af (patch)
treeccbeedf2455cbf75d2cdf66e27ca57a714b4b64c /lib/rack/file.rb
parentab67e70d82911c0c86dce737c7064d0bd6daf3d4 (diff)
downloadrack-beddb2a46626515690d9d2ea02b30904e8a346af.tar.gz
Allow Rack::File and Rack::Static to serve custom HTTP Headers
Diffstat (limited to 'lib/rack/file.rb')
-rw-r--r--lib/rack/file.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/rack/file.rb b/lib/rack/file.rb
index 6d91c484..fe5b114d 100644
--- a/lib/rack/file.rb
+++ b/lib/rack/file.rb
@@ -21,9 +21,14 @@ module Rack
 
     alias :to_path :path
 
-    def initialize(root, cache_control = nil)
+    def initialize(root, headers={})
       @root = root
-      @cache_control = cache_control
+      # Allow a cache_control string for backwards compatibility
+      if headers.instance_of? String
+        @headers = { 'Cache-Control' => headers }
+      else
+        @headers = headers
+      end
     end
 
     def call(env)
@@ -78,7 +83,9 @@ module Rack
         },
         env["REQUEST_METHOD"] == "HEAD" ? [] : self
       ]
-      response[1]['Cache-Control'] = @cache_control if @cache_control
+
+      # Set custom headers
+      @headers.each { |field, content| response[1][field] = content } if @headers
 
       # NOTE:
       #   We check via File::size? whether this file provides size info