summary refs log tree commit
diff options
context:
space:
mode:
-rw-r--r--lib/rack/directory.rb6
-rw-r--r--test/spec_directory.rb8
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/rack/directory.rb b/lib/rack/directory.rb
index 5baee3c8..c026c42a 100644
--- a/lib/rack/directory.rb
+++ b/lib/rack/directory.rb
@@ -59,9 +59,15 @@ table { width:100%%; }
     def initialize(root, app=nil)
       @root = ::File.expand_path(root)
       @app = app || Rack::File.new(@root)
+      @head = Rack::Head.new(lambda { |env| get env })
     end
 
     def call(env)
+      # strip body if this is a HEAD call
+      @head.call env
+    end
+
+    def get(env)
       script_name = env[SCRIPT_NAME]
       path_info = Utils.unescape_path(env[PATH_INFO])
 
diff --git a/test/spec_directory.rb b/test/spec_directory.rb
index 1a97e9e5..6ba0d406 100644
--- a/test/spec_directory.rb
+++ b/test/spec_directory.rb
@@ -130,4 +130,12 @@ describe Rack::Directory do
     res = mr.get("/script-path/cgi/test+directory/test+file")
     res.must_be :ok?
   end
+
+  it "return error when file not found for head request" do
+    res = Rack::MockRequest.new(Rack::Lint.new(app)).
+      head("/cgi/missing")
+
+    res.must_be :not_found?
+    res.body.must_be :empty?
+  end
 end