<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>actionpack/test/new_base/metal_test.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -47,7 +47,7 @@ module ActionController
     # and response object available. You might wish to control the
     # environment and response manually for performance reasons.
 
-    attr_internal :status, :headers, :content_type
+    attr_internal :status, :headers, :content_type, :app, :response
 
     def initialize(*)
       @_headers = {}
@@ -75,7 +75,34 @@ module ActionController
 
     # :api: private
     def to_a
-      [status, headers, response_body]
+      response ? response.to_a : [status, headers, response_body]
+    end
+
+    class ActionEndpoint
+      def initialize(controller, action)
+        @controller, @action = controller, action
+      end
+
+      def call(env)
+        controller = @controller.new.call(@action, env)
+      end
+    end
+
+    class ActionMiddleware
+      def initialize(controller, action)
+        @controller, @action = controller, action
+      end
+
+      def call(env)
+        controller = @controller.new
+        controller.app = @app
+        controller.call(@action, env)
+      end
+
+      def new(app)
+        @app = app
+        self
+      end
     end
 
     # Return a rack endpoint for the given action. Memoize the endpoint, so
@@ -89,9 +116,12 @@ module ActionController
     # Proc:: A rack application
     def self.action(name)
       @actions ||= {}
-      @actions[name.to_s] ||= proc do |env|
-        new.call(name, env)
-      end
+      @actions[name.to_s] ||= ActionEndpoint.new(self, name)
+    end
+
+    def self.middleware(name)
+      @middlewares ||= {}
+      @middlewares[name.to_s] ||= ActionMiddleware.new(self, name)
     end
   end
 end</diff>
      <filename>actionpack/lib/action_controller/metal.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@ module ActionController
     included do
       delegate :headers, :status=, :location=, :content_type=,
                :status, :location, :content_type, :to =&gt; &quot;@_response&quot;
-      attr_internal :request, :response
+      attr_internal :request
     end
 
     def call(name, env)
@@ -19,12 +19,6 @@ module ActionController
       @_params ||= @_request.parameters
     end
 
-    # :api: private
-    def to_a
-      @_response.prepare!
-      @_response.to_a
-    end
-
     def response_body=(body)
       response.body = body if response
       super</diff>
      <filename>actionpack/lib/action_controller/metal/rack_convenience.rb</filename>
    </modified>
    <modified>
      <diff>@@ -161,13 +161,16 @@ module ActionDispatch # :nodoc:
       headers[CONTENT_TYPE] = type
     end
 
-    def prepare!
+    def to_a
       assign_default_content_type_and_charset!
       handle_conditional_get!
       self[&quot;Set-Cookie&quot;] = @cookie.join(&quot;\n&quot;)
       self[&quot;ETag&quot;]       = @etag if @etag
+      super
     end
 
+    alias prepare! to_a
+
     def each(&amp;callback)
       if @body.respond_to?(:call)
         @writer = lambda { |x| callback.call(x) }</diff>
      <filename>actionpack/lib/action_dispatch/http/response.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>09fde6440a729e169e51c04f7caf0d19fe949c1d</id>
    </parent>
  </parents>
  <author>
    <name>Yehuda Katz + Carl Lerche</name>
    <login></login>
    <email>ykatz+clerche@engineyard.com</email>
  </author>
  <url>http://github.com/rails/rails/commit/c7ba911a43e513bd1adbee93f16d2b8efea7cc88</url>
  <id>c7ba911a43e513bd1adbee93f16d2b8efea7cc88</id>
  <committed-date>2009-08-25T12:14:31-07:00</committed-date>
  <authored-date>2009-08-25T12:14:31-07:00</authored-date>
  <message>ActionController::Metal can be a middleware</message>
  <tree>0a3f88da172575fb9d85980975cbbe41ed6bd53c</tree>
  <committer>
    <name>Yehuda Katz + Carl Lerche</name>
    <login></login>
    <email>ykatz+clerche@engineyard.com</email>
  </committer>
</commit>
