diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-08-27 15:56:16 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-08-27 15:56:16 -0300 |
commit | d395391e1dfae4531671fbb09911e6b9418474ba (patch) | |
tree | 65d679e11c15de32c18a4303d6dcb9f88f2a0925 /actionpack/lib/action_controller | |
parent | 286f47f3b034db4550110b9a0f9ff48dda29e807 (diff) | |
parent | c10396b1426fcddea35d88fe865846b8aaab5de4 (diff) | |
download | rails-d395391e1dfae4531671fbb09911e6b9418474ba.tar.gz rails-d395391e1dfae4531671fbb09911e6b9418474ba.tar.bz2 rails-d395391e1dfae4531671fbb09911e6b9418474ba.zip |
Merge commit 'rails/master'
Diffstat (limited to 'actionpack/lib/action_controller')
6 files changed, 56 insertions, 33 deletions
diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index aad9570237..51fbba3661 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -88,23 +88,6 @@ module ActionController 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 # multiple calls into MyController.action will return the same object # for the same action. @@ -118,10 +101,5 @@ module ActionController @actions ||= {} @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 --git a/actionpack/lib/action_controller/metal/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb index 2b62a1be85..0f35a7c040 100644 --- a/actionpack/lib/action_controller/metal/http_authentication.rb +++ b/actionpack/lib/action_controller/metal/http_authentication.rb @@ -115,7 +115,7 @@ module ActionController end def authenticate_with_http_basic(&login_procedure) - HttpAuthentication::Basic.authenticate(self, &login_procedure) + HttpAuthentication::Basic.authenticate(request, &login_procedure) end def request_http_basic_authentication(realm = "Application") @@ -123,9 +123,9 @@ module ActionController end end - def authenticate(controller, &login_procedure) - unless authorization(controller.request).blank? - login_procedure.call(*user_name_and_password(controller.request)) + def authenticate(request, &login_procedure) + unless authorization(request).blank? + login_procedure.call(*user_name_and_password(request)) end end @@ -150,7 +150,8 @@ module ActionController def authentication_request(controller, realm) controller.headers["WWW-Authenticate"] = %(Basic realm="#{realm.gsub(/"/, "")}") - controller.__send__ :render, :text => "HTTP Basic: Access denied.\n", :status => :unauthorized + controller.response_body = "HTTP Basic: Access denied.\n" + controller.status = 401 end end @@ -164,7 +165,7 @@ module ActionController # Authenticate with HTTP Digest, returns true or false def authenticate_with_http_digest(realm = "Application", &password_procedure) - HttpAuthentication::Digest.authenticate(self, realm, &password_procedure) + HttpAuthentication::Digest.authenticate(request, realm, &password_procedure) end # Render output including the HTTP Digest authentication header @@ -174,8 +175,8 @@ module ActionController end # Returns false on a valid response, true otherwise - def authenticate(controller, realm, &password_procedure) - authorization(controller.request) && validate_digest_response(controller.request, realm, &password_procedure) + def authenticate(request, realm, &password_procedure) + authorization(request) && validate_digest_response(request, realm, &password_procedure) end def authorization(request) @@ -243,7 +244,8 @@ module ActionController def authentication_request(controller, realm, message = nil) message ||= "HTTP Digest: Access denied.\n" authentication_header(controller, realm) - controller.__send__ :render, :text => message, :status => :unauthorized + controller.response_body = message + controller.status = 401 end # Uses an MD5 digest based on time to generate a value to be used only once. diff --git a/actionpack/lib/action_controller/metal/redirector.rb b/actionpack/lib/action_controller/metal/redirector.rb index 20060b001f..f79fd54acd 100644 --- a/actionpack/lib/action_controller/metal/redirector.rb +++ b/actionpack/lib/action_controller/metal/redirector.rb @@ -8,6 +8,9 @@ module ActionController end module Redirector + extend ActiveSupport::Concern + include AbstractController::Logger + def redirect_to(url, status) #:doc: raise AbstractController::DoubleRenderError if response_body logger.info("Redirected to #{url}") if logger && logger.info? diff --git a/actionpack/lib/action_controller/middleware.rb b/actionpack/lib/action_controller/middleware.rb new file mode 100644 index 0000000000..fac0ed2645 --- /dev/null +++ b/actionpack/lib/action_controller/middleware.rb @@ -0,0 +1,38 @@ +module ActionController + class Middleware < Metal + class ActionMiddleware + def initialize(controller) + @controller = controller + end + + def call(env) + controller = @controller.allocate + controller.send(:initialize) + controller.app = @app + controller._call(env) + end + + def app=(app) + @app = app + end + end + + def self.new(app) + middleware = ActionMiddleware.new(self) + middleware.app = app + middleware + end + + def _call(env) + @_env = env + @_request = ActionDispatch::Request.new(env) + @_response = ActionDispatch::Response.new + @_response.request = @_request + process(:index) + end + + def index + call(env) + end + end +end
\ No newline at end of file diff --git a/actionpack/lib/action_controller/routing/generation/url_rewriter.rb b/actionpack/lib/action_controller/routing/generation/url_rewriter.rb index 9717582b5e..52b66c9303 100644 --- a/actionpack/lib/action_controller/routing/generation/url_rewriter.rb +++ b/actionpack/lib/action_controller/routing/generation/url_rewriter.rb @@ -172,7 +172,7 @@ module ActionController path = rewrite_path(options) rewritten_url << ActionController::Base.relative_url_root.to_s unless options[:skip_relative_url_root] rewritten_url << (options[:trailing_slash] ? path.sub(/\?|\z/) { "/" + $& } : path) - rewritten_url << "##{options[:anchor]}" if options[:anchor] + rewritten_url << "##{CGI.escape(options[:anchor].to_param.to_s)}" if options[:anchor] rewritten_url end diff --git a/actionpack/lib/action_controller/testing/process.rb b/actionpack/lib/action_controller/testing/process.rb index 6bc7d60d76..4185b803c5 100644 --- a/actionpack/lib/action_controller/testing/process.rb +++ b/actionpack/lib/action_controller/testing/process.rb @@ -249,6 +249,7 @@ module ActionController #:nodoc: temporary_routes = ActionController::Routing::RouteSet.new ActionController::Routing.module_eval { const_set :Routes, temporary_routes } + ActionController::Dispatcher.router = temporary_routes yield temporary_routes ensure @@ -256,6 +257,7 @@ module ActionController #:nodoc: ActionController::Routing.module_eval { remove_const :Routes } end ActionController::Routing.const_set(:Routes, real_routes) if real_routes + ActionController::Dispatcher.router = ActionController::Routing::Routes end end -end
\ No newline at end of file +end |