Skip to content

Commit

Permalink
redirect in routes takes port into account [#3653 status:resolved]
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jan 5, 2010
1 parent b3900a2 commit e55d70a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Expand Up @@ -208,6 +208,7 @@ def redirect(*args, &block)
uri = URI.parse(path_proc.call(req.params))
uri.scheme ||= req.scheme
uri.host ||= req.host
uri.port ||= req.port unless req.port == 80

headers = {
'Location' => uri.to_s,
Expand Down
12 changes: 12 additions & 0 deletions actionpack/test/dispatch/routing_test.rb
Expand Up @@ -507,6 +507,18 @@ def test_redirect_with_complete_url
end
end

def test_redirect_with_port
previous_host, self.host = self.host, 'www.example.com:3000'
with_test_routes do
get '/account/login'
assert_equal 301, @response.status
assert_equal 'http://www.example.com:3000/login', @response.headers['Location']
assert_equal 'Moved Permanently', @response.body
end
ensure
self.host = previous_host
end

private
def with_test_routes
real_routes, temp_routes = ActionController::Routing::Routes, Routes
Expand Down

1 comment on commit e55d70a

@rizwanreza
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!

Please sign in to comment.