From b3900a29eb89b6b4613966c03282997fcc0cd6ac Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 5 Jan 2010 12:00:38 -0600 Subject: All router redirect helper to accept a full URI [#3653 state:resolved] --- actionpack/lib/action_dispatch/routing/mapper.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 8f33346a4f..8b46790fd2 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -200,13 +200,21 @@ module ActionDispatch path = args.shift || block path_proc = path.is_a?(Proc) ? path : proc { |params| path % params } status = options[:status] || 301 + body = 'Moved Permanently' lambda do |env| - req = Rack::Request.new(env) - params = path_proc.call(env["action_dispatch.request.path_parameters"]) - url = req.scheme + '://' + req.host + params - - [ status, {'Location' => url, 'Content-Type' => 'text/html'}, ['Moved Permanently'] ] + req = Request.new(env) + + uri = URI.parse(path_proc.call(req.params)) + uri.scheme ||= req.scheme + uri.host ||= req.host + + headers = { + 'Location' => uri.to_s, + 'Content-Type' => 'text/html', + 'Content-Length' => body.length.to_s + } + [ status, headers, [body] ] end end -- cgit v1.2.3