public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Add internal middleware stack to Dispatcher

  config.middleware.use Rack::Cache
josh (author)
Mon Dec 01 11:48:47 -0800 2008
commit  06ed8e451198b2296d8b2752741e259b4f995081
tree    9e7733152cb317178ea95bfbe423e98e252a98c3
parent  3c07a8828ede3d41000513af29c293ae2e2a49d4
...
57
58
59
 
60
61
62
...
57
58
59
60
61
62
63
0
@@ -57,6 +57,7 @@ module ActionController
0
   autoload :Integration, 'action_controller/integration'
0
   autoload :IntegrationTest, 'action_controller/integration'
0
   autoload :Layout, 'action_controller/layout'
0
+  autoload :MiddlewareStack, 'action_controller/middleware_stack'
0
   autoload :MimeResponds, 'action_controller/mime_responds'
0
   autoload :PolymorphicRoutes, 'action_controller/polymorphic_routes'
0
   autoload :RackRequest, 'action_controller/rack_process'
...
85
86
87
 
 
 
88
89
90
...
93
94
95
 
96
97
98
...
127
128
129
 
 
 
 
130
131
132
...
85
86
87
88
89
90
91
92
93
...
96
97
98
99
100
101
102
...
131
132
133
134
135
136
137
138
139
140
0
@@ -85,6 +85,9 @@ module ActionController
0
         end
0
     end
0
 
0
+    cattr_accessor :middleware
0
+    self.middleware = MiddlewareStack.new
0
+
0
     cattr_accessor :error_file_path
0
     self.error_file_path = Rails.public_path if defined?(Rails.public_path)
0
 
0
@@ -93,6 +96,7 @@ module ActionController
0
 
0
     def initialize(output = $stdout, request = nil, response = nil)
0
       @output, @request, @response = output, request, response
0
+      @app = @@middleware.build(lambda { |env| self._call(env) })
0
     end
0
 
0
     def dispatch_unlocked
0
@@ -127,6 +131,10 @@ module ActionController
0
     end
0
 
0
     def call(env)
0
+      @app.call(env)
0
+    end
0
+
0
+    def _call(env)
0
       @request = RackRequest.new(env)
0
       @response = RackResponse.new(@request)
0
       dispatch
...
881
882
883
 
 
 
 
 
884
885
886
...
881
882
883
884
885
886
887
888
889
890
891
0
@@ -881,6 +881,11 @@ Run `rake gems:install` to install the missing gems.
0
       end
0
     end
0
 
0
+    def middleware
0
+      require 'action_controller'
0
+      ActionController::Dispatcher.middleware
0
+    end
0
+
0
     def builtin_directories
0
       # Include builtins only in the development environment.
0
       (environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []

Comments

stefanoc Wed Dec 17 08:08:27 -0800 2008

It’s funny that so many people are saying that you’re doing the “embrace & extend” thing with Rack, yet nobody noticed this commit (event though it was featured prominently in a recent “This week on Edge Rails” post” ).