diff options
author | Jordan Owens <jkowens@gmail.com> | 2016-05-03 16:17:30 -0400 |
---|---|---|
committer | Jordan Owens <jkowens@gmail.com> | 2016-05-03 16:17:30 -0400 |
commit | 03ee5ec3c74b22fae7193b6ac45f5f4f0497e45f (patch) | |
tree | 874f1d50b2a67ab3aaab9cfea9d85e87614a1275 | |
parent | f3a108619037d7f1e51230a8437af8f23764eca7 (diff) | |
download | rack-03ee5ec3c74b22fae7193b6ac45f5f4f0497e45f.tar.gz |
Omit response body for HEAD requests to Rack::Directory
-rw-r--r-- | lib/rack/directory.rb | 6 | ||||
-rw-r--r-- | test/spec_directory.rb | 8 |
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 |