public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Boot out CGI Processor.

* Add ActionController::CGIHandler as a backwards compatible CGI wrapper around 
Rack.
* Also pull failsafe responder into ActionController::Failsafe middleware.
josh (author)
Thu Dec 04 18:39:36 -0800 2008
commit  9c9da6c892d715ca22c3cf51f50deb1d80029c66
tree    1605da4f53bb22b5f793c0d78161e46fdb8603bf
parent  27ebfd795ff106efae8cbe318d7b15b1a3c63b13
...
46
47
48
49
50
51
52
 
53
54
55
...
89
90
91
 
 
 
 
 
92
93
94
...
46
47
48
 
 
49
50
51
52
53
54
...
88
89
90
91
92
93
94
95
96
97
98
0
@@ -46,10 +46,9 @@ module ActionController
0
   autoload :Base, 'action_controller/base'
0
   autoload :Benchmarking, 'action_controller/benchmarking'
0
   autoload :Caching, 'action_controller/caching'
0
-  autoload :CgiRequest, 'action_controller/cgi_process'
0
-  autoload :CgiResponse, 'action_controller/cgi_process'
0
   autoload :Cookies, 'action_controller/cookies'
0
   autoload :Dispatcher, 'action_controller/dispatcher'
0
+  autoload :Failsafe, 'action_controller/failsafe'
0
   autoload :Filters, 'action_controller/filters'
0
   autoload :Flash, 'action_controller/flash'
0
   autoload :Helpers, 'action_controller/helpers'
0
@@ -89,6 +88,11 @@ module ActionController
0
   module Http
0
     autoload :Headers, 'action_controller/headers'
0
   end
0
+
0
+  # DEPRECATE: Remove CGI support
0
+  autoload :CgiRequest, 'action_controller/cgi_process'
0
+  autoload :CgiResponse, 'action_controller/cgi_process'
0
+  autoload :CGIHandler, 'action_controller/cgi_process'
0
 end
0
 
0
 class CGI
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
 
 
 
 
 
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
 
 
 
118
119
120
 
121
122
 
123
124
125
126
 
 
 
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
 
142
143
144
145
146
147
 
148
149
150
151
152
 
 
 
 
 
 
 
 
 
153
154
155
156
157
158
159
160
161
162
 
 
 
 
163
 
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
 
 
 
 
 
 
 
 
 
 
 
 
181
182
183
 
 
 
 
 
 
 
 
 
 
 
184
...
1
2
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
5
6
7
8
9
10
 
 
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
13
14
15
 
 
16
17
18
19
20
 
 
 
21
22
23
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
26
 
 
 
 
 
27
28
 
 
 
 
29
30
31
32
33
34
35
36
37
38
 
 
 
 
 
 
 
 
 
39
40
41
42
43
44
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
0
@@ -1,184 +1,72 @@
0
 require 'action_controller/cgi_ext'
0
 
0
 module ActionController #:nodoc:
0
-  class Base
0
-    # Process a request extracted from a CGI object and return a response. Pass false as <tt>session_options</tt> to disable
0
-    # sessions (large performance increase if sessions are not needed). The <tt>session_options</tt> are the same as for CGI::Session:
0
-    #
0
-    # * <tt>:database_manager</tt> - standard options are CGI::Session::FileStore, CGI::Session::MemoryStore, and CGI::Session::PStore
0
-    #   (default). Additionally, there is CGI::Session::DRbStore and CGI::Session::ActiveRecordStore. Read more about these in
0
-    #   lib/action_controller/session.
0
-    # * <tt>:session_key</tt> - the parameter name used for the session id. Defaults to '_session_id'.
0
-    # * <tt>:session_id</tt> - the session id to use.  If not provided, then it is retrieved from the +session_key+ cookie, or 
0
-    #   automatically generated for a new session.
0
-    # * <tt>:new_session</tt> - if true, force creation of a new session.  If not set, a new session is only created if none currently
0
-    #   exists.  If false, a new session is never created, and if none currently exists and the +session_id+ option is not set,
0
-    #   an ArgumentError is raised.
0
-    # * <tt>:session_expires</tt> - the time the current session expires, as a Time object.  If not set, the session will continue
0
-    #   indefinitely.
0
-    # * <tt>:session_domain</tt> - the hostname domain for which this session is valid. If not set, defaults to the hostname of the
0
-    #   server.
0
-    # * <tt>:session_secure</tt> - if +true+, this session will only work over HTTPS.
0
-    # * <tt>:session_path</tt> - the path for which this session applies.  Defaults to the directory of the CGI script.
0
-    # * <tt>:cookie_only</tt> - if +true+ (the default), session IDs will only be accepted from cookies and not from
0
-    #   the query string or POST parameters. This protects against session fixation attacks.
0
-    def self.process_cgi(cgi = CGI.new, session_options = {})
0
-      new.process_cgi(cgi, session_options)
0
-    end
0
-
0
-    def process_cgi(cgi, session_options = {}) #:nodoc:
0
-      process(CgiRequest.new(cgi, session_options), CgiResponse.new(cgi)).out
0
-    end
0
-  end
0
-
0
-  class CgiRequest < AbstractRequest #:nodoc:
0
-    attr_accessor :cgi, :session_options
0
-    class SessionFixationAttempt < StandardError #:nodoc:
0
-    end
0
-
0
-    DEFAULT_SESSION_OPTIONS = {
0
-      :database_manager => CGI::Session::CookieStore, # store data in cookie
0
-      :prefix           => "ruby_sess.",    # prefix session file names
0
-      :session_path     => "/",             # available to all paths in app
0
-      :session_key      => "_session_id",
0
-      :cookie_only      => true,
0
-      :session_http_only=> true
0
-    }
0
-
0
-    def initialize(cgi, session_options = {})
0
-      @cgi = cgi
0
-      @session_options = session_options
0
-      @env = @cgi.__send__(:env_table)
0
-      super()
0
-    end
0
-
0
-    def query_string
0
-      qs = @cgi.query_string if @cgi.respond_to?(:query_string)
0
-      if !qs.blank?
0
-        qs
0
-      else
0
-        super
0
-      end
0
-    end
0
-
0
-    def body_stream #:nodoc:
0
-      @cgi.stdinput
0
-    end
0
-
0
-    def cookies
0
-      @cgi.cookies.freeze
0
-    end
0
-
0
-    def session
0
-      unless defined?(@session)
0
-        if @session_options == false
0
-          @session = Hash.new
0
-        else
0
-          stale_session_check! do
0
-            if cookie_only? && query_parameters[session_options_with_string_keys['session_key']]
0
-              raise SessionFixationAttempt
0
-            end
0
-            case value = session_options_with_string_keys['new_session']
0
-              when true
0
-                @session = new_session
0
-              when false
0
-                begin
0
-                  @session = CGI::Session.new(@cgi, session_options_with_string_keys)
0
-                # CGI::Session raises ArgumentError if 'new_session' == false
0
-                # and no session cookie or query param is present.
0
-                rescue ArgumentError
0
-                  @session = Hash.new
0
-                end
0
-              when nil
0
-                @session = CGI::Session.new(@cgi, session_options_with_string_keys)
0
-              else
0
-                raise ArgumentError, "Invalid new_session option: #{value}"
0
-            end
0
-            @session['__valid_session']
0
-          end
0
+  class CGIHandler
0
+    module ProperStream
0
+      def each
0
+        while line = gets
0
+          yield line
0
         end
0
       end
0
-      @session
0
-    end
0
 
0
-    def reset_session
0
-      @session.delete if defined?(@session) && @session.is_a?(CGI::Session)
0
-      @session = new_session
0
-    end
0
-
0
-    def method_missing(method_id, *arguments)
0
-      @cgi.__send__(method_id, *arguments) rescue super
0
-    end
0
-
0
-    private
0
-      # Delete an old session if it exists then create a new one.
0
-      def new_session
0
-        if @session_options == false
0
-          Hash.new
0
+      def read(*args)
0
+        if args.empty?
0
+          super || ""
0
         else
0
-          CGI::Session.new(@cgi, session_options_with_string_keys.merge("new_session" => false)).delete rescue nil
0
-          CGI::Session.new(@cgi, session_options_with_string_keys.merge("new_session" => true))
0
+          super
0
         end
0
       end
0
+    end
0
 
0
-      def cookie_only?
0
-        session_options_with_string_keys['cookie_only']
0
-      end
0
+    def self.dispatch_cgi(app, cgi, out = $stdout)
0
+      env = cgi.__send__(:env_table)
0
+      env.delete "HTTP_CONTENT_LENGTH"
0
 
0
-      def stale_session_check!
0
-        yield
0
-      rescue ArgumentError => argument_error
0
-        if argument_error.message =~ %r{undefined class/module ([\w:]*\w)}
0
-          begin
0
-            # Note that the regexp does not allow $1 to end with a ':'
0
-            $1.constantize
0
-          rescue LoadError, NameError => const_error
0
-            raise ActionController::SessionRestoreError, <<-end_msg
0
-Session contains objects whose class definition isn\'t available.
0
-Remember to require the classes for all objects kept in the session.
0
-(Original exception: #{const_error.message} [#{const_error.class}])
0
-end_msg
0
-          end
0
+      cgi.stdinput.extend ProperStream
0
 
0
-          retry
0
-        else
0
-          raise
0
-        end
0
-      end
0
+      env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
0
 
0
-      def session_options_with_string_keys
0
-        @session_options_with_string_keys ||= DEFAULT_SESSION_OPTIONS.merge(@session_options).stringify_keys
0
-      end
0
-  end
0
+      env.update({
0
+        "rack.version" => [0,1],
0
+        "rack.input" => cgi.stdinput,
0
+        "rack.errors" => $stderr,
0
+        "rack.multithread" => false,
0
+        "rack.multiprocess" => true,
0
+        "rack.run_once" => false,
0
+        "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
0
+      })
0
 
0
-  class CgiResponse < AbstractResponse #:nodoc:
0
-    def initialize(cgi)
0
-      @cgi = cgi
0
-      super()
0
-    end
0
-
0
-    def out(output = $stdout)
0
-      output.binmode      if output.respond_to?(:binmode)
0
-      output.sync = false if output.respond_to?(:sync=)
0
+      env["QUERY_STRING"] ||= ""
0
+      env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
0
+      env["REQUEST_PATH"] ||= "/"
0
+      env.delete "PATH_INFO" if env["PATH_INFO"] == ""
0
 
0
+      status, headers, body = app.call(env)
0
       begin
0
-        output.write(@cgi.header(@headers))
0
-
0
-        if @cgi.__send__(:env_table)['REQUEST_METHOD'] == 'HEAD'
0
-          return
0
-        elsif @body.respond_to?(:call)
0
-          # Flush the output now in case the @body Proc uses
0
-          # #syswrite.
0
-          output.flush if output.respond_to?(:flush)
0
-          @body.call(self, output)
0
-        else
0
-          output.write(@body)
0
-        end
0
-
0
-        output.flush if output.respond_to?(:flush)
0
-      rescue Errno::EPIPE, Errno::ECONNRESET
0
-        # lost connection to parent process, ignore output
0
+        out.binmode if out.respond_to?(:binmode)
0
+        out.sync = false if out.respond_to?(:sync=)
0
+
0
+        headers['Status'] = status.to_s
0
+        out.write(cgi.header(headers))
0
+
0
+        body.each { |part|
0
+          out.write part
0
+          out.flush if out.respond_to?(:flush)
0
+        }
0
+      ensure
0
+        body.close if body.respond_to?(:close)
0
       end
0
     end
0
   end
0
+
0
+  class CgiRequest #:nodoc:
0
+    DEFAULT_SESSION_OPTIONS = {
0
+      :database_manager  => CGI::Session::CookieStore,
0
+      :prefix            => "ruby_sess.",
0
+      :session_path      => "/",
0
+      :session_key       => "_session_id",
0
+      :cookie_only       => true,
0
+      :session_http_only => true
0
+    }
0
+  end
0
 end
...
24
25
26
27
28
 
29
30
31
...
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
 
93
94
95
96
 
97
98
99
...
120
121
122
 
123
124
125
126
127
128
129
130
 
131
132
133
...
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
 
 
175
176
177
178
179
180
181
 
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
 
197
198
199
...
24
25
26
 
 
27
28
29
30
...
42
43
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
46
47
48
 
 
 
49
50
51
52
53
54
55
56
57
...
78
79
80
81
82
 
 
 
 
 
 
 
83
84
85
86
...
113
114
115
 
 
 
 
 
 
 
 
 
116
117
 
118
119
120
121
122
123
124
125
 
126
127
128
129
 
 
 
 
 
 
 
 
 
 
130
 
131
132
133
134
0
@@ -24,8 +24,7 @@ module ActionController
0
         end
0
       end
0
 
0
-      # Backward-compatible class method takes CGI-specific args. Deprecated
0
-      # in favor of Dispatcher.new(output, request, response).dispatch.
0
+      # DEPRECATE: Remove CGI support
0
       def dispatch(cgi = nil, session_options = CgiRequest::DEFAULT_SESSION_OPTIONS, output = $stdout)
0
         new(output).dispatch_cgi(cgi, session_options)
0
       end
0
@@ -43,57 +42,16 @@ module ActionController
0
         callback = ActiveSupport::Callbacks::Callback.new(:prepare_dispatch, block, :identifier => identifier)
0
         @prepare_dispatch_callbacks.replace_or_append!(callback)
0
       end
0
-
0
-      # If the block raises, send status code as a last-ditch response.
0
-      def failsafe_response(fallback_output, status, originating_exception = nil)
0
-        yield
0
-      rescue Exception => exception
0
-        begin
0
-          log_failsafe_exception(status, originating_exception || exception)
0
-          body = failsafe_response_body(status)
0
-          fallback_output.write "Status: #{status}\r\nContent-Type: text/html\r\n\r\n#{body}"
0
-          nil
0
-        rescue Exception => failsafe_error # Logger or IO errors
0
-          $stderr.puts "Error during failsafe response: #{failsafe_error}"
0
-          $stderr.puts "(originally #{originating_exception})" if originating_exception
0
-        end
0
-      end
0
-
0
-      private
0
-        def failsafe_response_body(status)
0
-          error_path = "#{error_file_path}/#{status.to_s[0..2]}.html"
0
-
0
-          if File.exist?(error_path)
0
-            File.read(error_path)
0
-          else
0
-            "<html><body><h1>#{status}</h1></body></html>"
0
-          end
0
-        end
0
-
0
-        def log_failsafe_exception(status, exception)
0
-          message = "/!\\ FAILSAFE /!\\  #{Time.now}\n  Status: #{status}\n"
0
-          message << "  #{exception}\n    #{exception.backtrace.join("\n    ")}" if exception
0
-          failsafe_logger.fatal message
0
-        end
0
-
0
-        def failsafe_logger
0
-          if defined?(::RAILS_DEFAULT_LOGGER) && !::RAILS_DEFAULT_LOGGER.nil?
0
-            ::RAILS_DEFAULT_LOGGER
0
-          else
0
-            Logger.new($stderr)
0
-          end
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
+    self.middleware.use "ActionController::Failsafe"
0
 
0
     include ActiveSupport::Callbacks
0
     define_callbacks :prepare_dispatch, :before_dispatch, :after_dispatch
0
 
0
+    # DEPRECATE: Remove arguments
0
     def initialize(output = $stdout, request = nil, response = nil)
0
       @output, @request, @response = output, request, response
0
       @app = @@middleware.build(lambda { |env| self.dup._call(env) })
0
@@ -120,14 +78,9 @@ module ActionController
0
       end
0
     end
0
 
0
+    # DEPRECATE: Remove CGI support
0
     def dispatch_cgi(cgi, session_options)
0
-      if cgi ||= self.class.failsafe_response(@output, '400 Bad Request') { CGI.new }
0
-        @request = CgiRequest.new(cgi, session_options)
0
-        @response = CgiResponse.new(cgi)
0
-        dispatch
0
-      end
0
-    rescue Exception => exception
0
-      failsafe_rescue exception
0
+      CGIHandler.dispatch_cgi(self, cgi, @output)
0
     end
0
 
0
     def call(env)
0
@@ -160,40 +113,22 @@ module ActionController
0
       Base.logger.flush
0
     end
0
 
0
-    def mark_as_test_request!
0
-      @test_request = true
0
-      self
0
-    end
0
-
0
-    def test_request?
0
-      @test_request
0
-    end
0
-
0
     def checkin_connections
0
       # Don't return connection (and peform implicit rollback) if this request is a part of integration test
0
-      return if test_request?
0
+      # TODO: This callback should have direct access to env
0
+      return if @request.key?("action_controller.test")
0
       ActiveRecord::Base.clear_active_connections!
0
     end
0
 
0
     protected
0
       def handle_request
0
         @controller = Routing::Routes.recognize(@request)
0
-        @controller.process(@request, @response).out(@output)
0
+        @controller.process(@request, @response).out
0
       end
0
 
0
       def failsafe_rescue(exception)
0
-        if @test_request
0
-          process_with_exception(exception)
0
-        else
0
-          self.class.failsafe_response(@output, '500 Internal Server Error', exception) do
0
-            process_with_exception(exception)
0
-          end
0
-        end
0
-      end
0
-
0
-      def process_with_exception(exception)
0
         if @controller ||= (::ApplicationController rescue Base)
0
-          @controller.process_with_exception(@request, @response, exception).out(@output)
0
+          @controller.process_with_exception(@request, @response, exception).out
0
         else
0
           raise exception
0
         end
...
257
258
259
260
 
 
261
262
263
...
273
274
275
276
 
277
278
279
...
257
258
259
 
260
261
262
263
264
...
274
275
276
 
277
278
279
280
0
@@ -257,7 +257,8 @@ module ActionController
0
             "CONTENT_LENGTH" => data ? data.length.to_s : nil,
0
             "HTTP_COOKIE"    => encode_cookies,
0
             "HTTPS"          => https? ? "on" : "off",
0
-            "HTTP_ACCEPT"    => accept
0
+            "HTTP_ACCEPT"    => accept,
0
+            "action_controller.test" => true
0
           )
0
 
0
           (headers || {}).each do |key, value|
0
@@ -273,7 +274,7 @@ module ActionController
0
           ActionController::Base.clear_last_instantiation!
0
 
0
           env['rack.input'] = data.is_a?(IO) ? data : StringIO.new(data || '')
0
-          @status, @headers, result_body = ActionController::Dispatcher.new.mark_as_test_request!.call(env)
0
+          @status, @headers, result_body = ActionController::Dispatcher.new.call(env)
0
           @request_count += 1
0
 
0
           @controller = ActionController::Base.last_instantiation
...
164
165
166
167
 
168
169
170
...
164
165
166
 
167
168
169
170
0
@@ -164,7 +164,7 @@ end_msg
0
       @status || super
0
     end
0
 
0
-    def out(output = $stdout, &block)
0
+    def out(&block)
0
       # Nasty hack because CGI sessions are closed after the normal
0
       # prepare! statement
0
       set_cookies!
...
6
7
8
9
10
11
12
...
16
17
18
19
 
20
21
22
...
25
26
27
28
 
29
30
31
32
33
 
34
35
36
37
38
 
39
40
41
...
51
52
53
54
55
56
57
58
59
 
 
 
 
 
 
 
 
 
 
60
61
62
...
77
78
79
80
 
81
82
83
...
92
93
94
95
96
97
98
99
100
101
 
 
102
103
 
104
105
106
...
6
7
8
 
9
10
11
...
15
16
17
 
18
19
20
21
...
24
25
26
 
27
28
29
30
31
 
32
33
34
35
36
 
37
38
39
40
...
50
51
52
 
 
 
 
 
 
53
54
55
56
57
58
59
60
61
62
63
64
65
...
80
81
82
 
83
84
85
86
...
95
96
97
 
 
 
 
 
 
 
98
99
100
 
101
102
103
104
0
@@ -6,7 +6,6 @@ class DispatcherTest < Test::Unit::TestCase
0
   Dispatcher = ActionController::Dispatcher
0
 
0
   def setup
0
-    @output = StringIO.new
0
     ENV['REQUEST_METHOD'] = 'GET'
0
 
0
     # Clear callbacks as they are redefined by Dispatcher#define_dispatcher_callbacks
0
@@ -16,7 +15,7 @@ class DispatcherTest < Test::Unit::TestCase
0
 
0
     Dispatcher.stubs(:require_dependency)
0
 
0
-    @dispatcher = Dispatcher.new(@output)
0
+    @dispatcher = Dispatcher.new
0
   end
0
 
0
   def teardown
0
@@ -25,17 +24,17 @@ class DispatcherTest < Test::Unit::TestCase
0
 
0
   def test_clears_dependencies_after_dispatch_if_in_loading_mode
0
     ActiveSupport::Dependencies.expects(:clear).once
0
-    dispatch(@output, false)
0
+    dispatch(false)
0
   end
0
 
0
   def test_reloads_routes_before_dispatch_if_in_loading_mode
0
     ActionController::Routing::Routes.expects(:reload).once
0
-    dispatch(@output, false)
0
+    dispatch(false)
0
   end
0
 
0
   def test_clears_asset_tag_cache_before_dispatch_if_in_loading_mode
0
     ActionView::Helpers::AssetTagHelper::AssetTag::Cache.expects(:clear).once
0
-    dispatch(@output, false)
0
+    dispatch(false)
0
   end
0
 
0
   def test_leaves_dependencies_after_dispatch_if_not_in_loading_mode
0
@@ -51,12 +50,16 @@ class DispatcherTest < Test::Unit::TestCase
0
   end
0
 
0
   def test_failsafe_response
0
-    CGI.expects(:new).raises('some multipart parsing failure')
0
-    Dispatcher.expects(:log_failsafe_exception)
0
-
0
-    assert_nothing_raised { dispatch }
0
-
0
-    assert_equal "Status: 400 Bad Request\r\nContent-Type: text/html\r\n\r\n<html><body><h1>400 Bad Request</h1></body></html>", @output.string
0
+    Dispatcher.any_instance.expects(:dispatch_unlocked).raises('b00m')
0
+    ActionController::Failsafe.any_instance.expects(:log_failsafe_exception)
0
+
0
+    assert_nothing_raised do
0
+      assert_equal [
0
+        500,
0
+        {"Content-Type" => "text/html"},
0
+        "<html><body><h1>500 Internal Server Error</h1></body></html>"
0
+      ], dispatch
0
+    end
0
   end
0
 
0
   def test_prepare_callbacks
0
@@ -77,7 +80,7 @@ class DispatcherTest < Test::Unit::TestCase
0
 
0
     # Make sure they are only run once
0
     a = b = c = nil
0
-    @dispatcher.send :dispatch
0
+    dispatch
0
     assert_nil a || b || c
0
   end
0
 
0
@@ -92,15 +95,10 @@ class DispatcherTest < Test::Unit::TestCase
0
   end
0
 
0
   private
0
-    def dispatch(output = @output, cache_classes = true)
0
-      controller = mock
0
-      controller.stubs(:process).returns(controller)
0
-      controller.stubs(:out).with(output).returns('response')
0
-
0
-      ActionController::Routing::Routes.stubs(:recognize).returns(controller)
0
-
0
+    def dispatch(cache_classes = true)
0
+      Dispatcher.any_instance.stubs(:handle_request).returns([200, {}, 'response'])
0
       Dispatcher.define_dispatcher_callbacks(cache_classes)
0
-      Dispatcher.dispatch(nil, {}, output)
0
+      @dispatcher.call({})
0
     end
0
 
0
     def assert_subclasses(howmany, klass, message = klass.subclasses.inspect)
...
230
231
232
233
234
235
236
237
238
239
240
 
241
242
243
...
258
259
260
261
 
262
263
264
...
274
275
276
277
 
278
279
280
...
294
295
296
297
298
299
300
...
317
318
319
320
 
321
322
...
230
231
232
 
233
234
235
236
237
238
 
239
240
241
242
...
257
258
259
 
260
261
262
263
...
273
274
275
 
276
277
278
279
...
293
294
295
 
296
297
298
...
315
316
317
 
318
319
320
0
@@ -230,14 +230,13 @@ class RackResponseTest < BaseRackTest
0
   def setup
0
     super
0
     @response = ActionController::RackResponse.new(@request)
0
-    @output = StringIO.new('')
0
   end
0
 
0
   def test_simple_output
0
     @response.body = "Hello, World!"
0
     @response.prepare!
0
 
0
-    status, headers, body = @response.out(@output)
0
+    status, headers, body = @response.out
0
     assert_equal "200 OK", status
0
     assert_equal({
0
       "Content-Type" => "text/html; charset=utf-8",
0
@@ -258,7 +257,7 @@ class RackResponseTest < BaseRackTest
0
     end
0
     @response.prepare!
0
 
0
-    status, headers, body = @response.out(@output)
0
+    status, headers, body = @response.out
0
     assert_equal "200 OK", status
0
     assert_equal({"Content-Type" => "text/html; charset=utf-8", "Cache-Control" => "no-cache", "Set-Cookie" => []}, headers)
0
 
0
@@ -274,7 +273,7 @@ class RackResponseTest < BaseRackTest
0
     @response.body = "Hello, World!"
0
     @response.prepare!
0
 
0
-    status, headers, body = @response.out(@output)
0
+    status, headers, body = @response.out
0
     assert_equal "200 OK", status
0
     assert_equal({
0
       "Content-Type" => "text/html; charset=utf-8",
0
@@ -294,7 +293,6 @@ class RackResponseHeadersTest < BaseRackTest
0
   def setup
0
     super
0
     @response = ActionController::RackResponse.new(@request)
0
-    @output = StringIO.new('')
0
     @response.headers['Status'] = "200 OK"
0
   end
0
 
0
@@ -317,6 +315,6 @@ class RackResponseHeadersTest < BaseRackTest
0
   private
0
     def response_headers
0
       @response.prepare!
0
-      @response.out(@output)[1]
0
+      @response.out[1]
0
     end
0
 end
...
637
638
639
640
 
641
642
643
...
649
650
651
652
 
653
654
655
...
637
638
639
 
640
641
642
643
...
649
650
651
 
652
653
654
655
0
@@ -637,7 +637,7 @@ class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase
0
     input = {
0
       "customers[boston][first][name]" => [ "David" ],
0
       "something_else" => [ "blah" ],
0
-      "logo" => [ File.new(File.dirname(__FILE__) + "/cgi_test.rb").path ]
0
+      "logo" => [ File.new(File.dirname(__FILE__) + "/rack_test.rb").path ]
0
     }
0
 
0
     expected_output = {
0
@@ -649,7 +649,7 @@ class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase
0
         }
0
       },
0
       "something_else" => "blah",
0
-      "logo" => File.new(File.dirname(__FILE__) + "/cgi_test.rb").path,
0
+      "logo" => File.new(File.dirname(__FILE__) + "/rack_test.rb").path,
0
     }
0
 
0
     assert_equal expected_output, ActionController::AbstractRequest.parse_request_parameters(input)

Comments

clemens Thu Dec 04 23:43:25 -0800 2008

Finally …

boblmartens Fri Dec 05 00:20:32 -0800 2008

Excellent. Leaner and meaner!

raggi Fri Dec 05 04:12:26 -0800 2008

it’s not finished yet, but:

http://github.com/raggi/rails/commit/935d49846de3b194e61b049cd220e54fd11002cf

I’ll have to merge this one :-/

josh Fri Dec 05 07:41:22 -0800 2008

@raggi we need to get in touch. I don’t want to start hacking on some of that stuff if you’ve already done the hard work.

Please email me, josh at joshpeek dot com