diff options
-rw-r--r-- | .travis.yml | 4 | ||||
-rw-r--r-- | lib/rack/directory.rb | 6 | ||||
-rw-r--r-- | lib/rack/request.rb | 32 | ||||
-rw-r--r-- | test/spec_directory.rb | 8 |
4 files changed, 36 insertions, 14 deletions
diff --git a/.travis.yml b/.travis.yml index 486635f9..cf999939 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,8 +20,8 @@ before_install: script: bundle exec rake ci rvm: - - 2.2.4 - - 2.3.0 + - 2.2.5 + - 2.3.1 - ruby-head - rbx-2 - jruby-9.0.4.0 diff --git a/lib/rack/directory.rb b/lib/rack/directory.rb index e642975c..89cfe807 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/lib/rack/request.rb b/lib/rack/request.rb index a76f15cd..0a64f69e 100644 --- a/lib/rack/request.rb +++ b/lib/rack/request.rb @@ -16,18 +16,6 @@ module Rack super(env) end - # shortcut for <tt>request.params[key]</tt> - def [](key) - params[key.to_s] - end - - # shortcut for <tt>request.params[key] = value</tt> - # - # Note that modifications will not be persisted in the env. Use update_param or delete_param if you want to destructively modify params. - def []=(key, value) - params[key.to_s] = value - end - # like Hash#values_at def values_at(*keys) keys.map{|key| params[key] } @@ -437,6 +425,26 @@ module Rack ip =~ /\A127\.0\.0\.1\Z|\A(10|172\.(1[6-9]|2[0-9]|30|31)|192\.168)\.|\A::1\Z|\Afd[0-9a-f]{2}:.+|\Alocalhost\Z|\Aunix\Z|\Aunix:/i end + # shortcut for <tt>request.params[key]</tt> + def [](key) + if $verbose + warn("Request#[] is deprecated and will be removed in a future version of Rack. Please use request.params[] instead") + end + + params[key.to_s] + end + + # shortcut for <tt>request.params[key] = value</tt> + # + # Note that modifications will not be persisted in the env. Use update_param or delete_param if you want to destructively modify params. + def []=(key, value) + if $verbose + warn("Request#[]= is deprecated and will be removed in a future version of Rack. Please use request.params[]= instead") + end + + params[key.to_s] = value + end + private def default_session; {}; end diff --git a/test/spec_directory.rb b/test/spec_directory.rb index 3801b9d7..42bdea9f 100644 --- a/test/spec_directory.rb +++ b/test/spec_directory.rb @@ -137,4 +137,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 |