Skip to content

Commit

Permalink
Do not append the port for a SSL redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
fbernier committed Aug 10, 2016
1 parent a0dbf9b commit 56c271d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rack/www.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def prepare_url(env)

def extract_host(env)
[env['SERVER_NAME'].to_s.gsub(/^(#{@subdomain}\.|www\.)/, ''),
env['SERVER_PORT'] == '80' ? '' : ":#{env['SERVER_PORT']}",
['80', '443'].include?(env['SERVER_PORT']) ? '' : ":#{env['SERVER_PORT']}",
env['PATH_INFO'],
env['QUERY_STRING'].empty? ? '' : '?' + env['QUERY_STRING'].to_s]
end
Expand Down
6 changes: 6 additions & 0 deletions test/www_false_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ def test_www_false
last_response.headers['Location']
end

def test_www_false_with_ssl
get 'https://www.example.com/'
assert_equal 'https://example.com/',
last_response.headers['Location']
end

def test_www_false_with_path
get 'http://www.example.com/path/1'
assert_equal 'http://example.com/path/1',
Expand Down
5 changes: 5 additions & 0 deletions test/www_true_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ def test_www_true
assert_equal 'http://www.example.com/', last_response.headers['Location']
end

def test_www_true_with_ssl
get 'https://example.com/'
assert_equal 'https://www.example.com/', last_response.headers['Location']
end

def test_www_true_with_path
get 'http://example.com/path/1'
assert_equal 'http://www.example.com/path/1',
Expand Down

0 comments on commit 56c271d

Please sign in to comment.