Skip to content
This repository
Browse code

Remove ActionDispatch::Head middleware in favor of Rack::Head

Closes #7110 there's more work to do on rack-cache issue 69
  • Loading branch information...
commit 449039a86d802871b707dfb51ac1ed96d53526f9 1 parent 998189a
Santiago Pastorino authored July 23, 2012
4  actionpack/lib/action_dispatch/http/request.rb
@@ -119,9 +119,9 @@ def delete?
119 119
     end
120 120
 
121 121
     # Is this a HEAD request?
122  
-    # Equivalent to <tt>request.method_symbol == :head</tt>.
  122
+    # Equivalent to <tt>request.request_method_symbol == :head</tt>.
123 123
     def head?
124  
-      HTTP_METHOD_LOOKUP[method] == :head
  124
+      HTTP_METHOD_LOOKUP[request_method] == :head
125 125
     end
126 126
 
127 127
     # Provides access to the request's HTTP headers, for example:
18  actionpack/lib/action_dispatch/middleware/head.rb
... ...
@@ -1,18 +0,0 @@
1  
-module ActionDispatch
2  
-  class Head
3  
-    def initialize(app)
4  
-      @app = app
5  
-    end
6  
-
7  
-    def call(env)
8  
-      if env["REQUEST_METHOD"] == "HEAD"
9  
-        env["REQUEST_METHOD"] = "GET"
10  
-        env["rack.methodoverride.original_method"] = "HEAD"
11  
-        status, headers, _ = @app.call(env)
12  
-        [status, headers, []]
13  
-      else
14  
-        @app.call(env)
15  
-      end
16  
-    end
17  
-  end
18  
-end
2  actionpack/test/abstract_unit.rb
@@ -171,7 +171,7 @@ def self.build_app(routes = nil)
171 171
       middleware.use "ActionDispatch::ParamsParser"
172 172
       middleware.use "ActionDispatch::Cookies"
173 173
       middleware.use "ActionDispatch::Flash"
174  
-      middleware.use "ActionDispatch::Head"
  174
+      middleware.use "Rack::Head"
175 175
       yield(middleware) if block_given?
176 176
     end
177 177
   end
8  actionpack/test/dispatch/request_test.rb
@@ -461,14 +461,6 @@ def url_for(options = {})
461 461
     end
462 462
   end
463 463
 
464  
-  test "head masquerading as get" do
465  
-    request = stub_request 'REQUEST_METHOD' => 'GET', "rack.methodoverride.original_method" => "HEAD"
466  
-    assert_equal "HEAD", request.method
467  
-    assert_equal "GET",  request.request_method
468  
-    assert request.get?
469  
-    assert request.head?
470  
-  end
471  
-
472 464
   test "post masquerading as patch" do
473 465
     request = stub_request 'REQUEST_METHOD' => 'PATCH', "rack.methodoverride.original_method" => "POST"
474 466
     assert_equal "POST", request.method
2  railties/lib/rails/application.rb
@@ -310,7 +310,7 @@ def default_middleware_stack #:nodoc:
310 310
         end
311 311
 
312 312
         middleware.use ::ActionDispatch::ParamsParser
313  
-        middleware.use ::ActionDispatch::Head
  313
+        middleware.use ::Rack::Head
314 314
         middleware.use ::Rack::ConditionalGet
315 315
         middleware.use ::Rack::ETag, "no-cache"
316 316
 
2  railties/test/application/middleware_test.rb
@@ -45,7 +45,7 @@ def app
45 45
         "ActionDispatch::Session::CookieStore",
46 46
         "ActionDispatch::Flash",
47 47
         "ActionDispatch::ParamsParser",
48  
-        "ActionDispatch::Head",
  48
+        "Rack::Head",
49 49
         "Rack::ConditionalGet",
50 50
         "Rack::ETag",
51 51
         "ActionDispatch::BestStandardsSupport"
8  railties/test/application/rack/logger_test.rb
@@ -26,12 +26,18 @@ def logs
26 26
         @logs ||= @logger.logged(:info)
27 27
       end
28 28
 
29  
-      test "logger logs proper HTTP verb and path" do
  29
+      test "logger logs proper HTTP GET verb and path" do
30 30
         get "/blah"
31 31
         wait
32 32
         assert_match(/^Started GET "\/blah"/, logs[0])
33 33
       end
34 34
 
  35
+      test "logger logs proper HTTP HEAD verb and path" do
  36
+        head "/blah"
  37
+        wait
  38
+        assert_match(/^Started HEAD "\/blah"/, logs[0])
  39
+      end
  40
+
35 41
       test "logger logs HTTP verb override" do
36 42
         post "/", {:_method => 'put'}
37 43
         wait

0 notes on commit 449039a

Please sign in to comment.
Something went wrong with that request. Please try again.