From 6bbe965ccdcef2d7e713e65175722718d325b2bd Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Wed, 27 May 2009 10:40:43 +0200 Subject: Reduce the cost of using ActionController::Http significantly by: * Removing the dependency on AD::Request and AD::Response * Moving the logic for the request and response object into a new module that is included by default. * Changing Renderer and Redirector to use self.headers, self.content_type, and self.status, which have very basic default implementations on AC::Http. When RackConvenience is included (which it is by default on AC::Base), the full Request/Response logic is used instead of the simple logic. --- actionpack/lib/action_controller/new_base/http.rb | 42 ++++++++++++++++------- 1 file changed, 29 insertions(+), 13 deletions(-) (limited to 'actionpack/lib/action_controller/new_base/http.rb') diff --git a/actionpack/lib/action_controller/new_base/http.rb b/actionpack/lib/action_controller/new_base/http.rb index 2525e221a6..7ff490bb9c 100644 --- a/actionpack/lib/action_controller/new_base/http.rb +++ b/actionpack/lib/action_controller/new_base/http.rb @@ -6,7 +6,7 @@ module ActionController abstract! # :api: public - attr_internal :request, :response, :params + attr_internal :params, :env # :api: public def self.controller_name @@ -36,32 +36,48 @@ module ActionController controller.call(env).to_rack end - delegate :headers, :to => "@_response" + # The details below can be overridden to support a specific + # Request and Response object. The default ActionController::Base + # implementation includes RackConvenience, which makes a request + # and response object available. You might wish to control the + # environment and response manually for performance reasons. - def params - @_params ||= @_request.parameters + attr_internal :status, :headers, :content_type + + def initialize(*) + @_headers = {} + super + end + + # Basic implements for content_type=, location=, and headers are + # provided to reduce the dependency on the RackConvenience module + # in Renderer and Redirector. + + def content_type=(type) + headers["Content-Type"] = type.to_s + end + + def location=(url) + headers["Location"] = url end # :api: private def call(name, env) - @_request = ActionDispatch::Request.new(env) - @_response = ActionDispatch::Response.new - @_response.request = request + @_env = env process(name) to_rack end + # :api: private + def to_rack + [status, headers, response_body] + end + def self.action(name) @actions ||= {} @actions[name.to_s] ||= proc do |env| new.call(name, env) end end - - # :api: private - def to_rack - @_response.prepare! - @_response.to_a - end end end -- cgit v1.2.3