aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing/mapper.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2010-01-05 12:00:38 -0600
committerJoshua Peek <josh@joshpeek.com>2010-01-05 12:00:38 -0600
commitb3900a29eb89b6b4613966c03282997fcc0cd6ac (patch)
tree8c0eb99f32302d57e39d3217060836635ab4c15f /actionpack/lib/action_dispatch/routing/mapper.rb
parent8ff4faf66a332b24d1a82a4e62daeabc06945dcf (diff)
downloadrails-b3900a29eb89b6b4613966c03282997fcc0cd6ac.tar.gz
rails-b3900a29eb89b6b4613966c03282997fcc0cd6ac.tar.bz2
rails-b3900a29eb89b6b4613966c03282997fcc0cd6ac.zip
All router redirect helper to accept a full URI [#3653 state:resolved]
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/mapper.rb')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb18
1 files changed, 13 insertions, 5 deletions
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