Permalink
Browse files

Merge pull request #14665 from andrielfn/avoid-uri-parsing

Avoid URI parsing
  • Loading branch information...
2 parents 7142ff8 + 85e424d commit 7b75b678cf11a1aed7927a9db42fb60a38726450 @rafaelfranca rafaelfranca committed Apr 9, 2014
Showing with 15 additions and 5 deletions.
  1. +8 −5 actionpack/lib/action_dispatch/middleware/ssl.rb
  2. +7 −0 actionpack/test/dispatch/ssl_test.rb
@@ -32,11 +32,14 @@ def call(env)
private
def redirect_to_https(request)
- url = URI(request.url)
- url.scheme = "https"
- url.host = @host if @host
- url.port = @port if @port
- headers = { 'Content-Type' => 'text/html', 'Location' => url.to_s }
+ host = @host || request.host
+ port = @port || request.port
+
+ location = "https://#{host}"
+ location << ":#{port}" if port != 80
+ location << request.fullpath
+
+ headers = { 'Content-Type' => 'text/html', 'Location' => location }
[301, headers, []]
end
@@ -196,6 +196,13 @@ def test_redirect_to_host_and_port
response.headers['Location']
end
+ def test_redirect_to_host_with_port
+ self.app = ActionDispatch::SSL.new(default_app, :host => "ssl.example.org:443")
+ get "http://example.org/path?key=value"
+ assert_equal "https://ssl.example.org:443/path?key=value",
+ response.headers['Location']
+ end
+
def test_redirect_to_secure_host_when_on_subdomain
self.app = ActionDispatch::SSL.new(default_app, :host => "ssl.example.org")
get "http://ssl.example.org/path?key=value"

0 comments on commit 7b75b67

Please sign in to comment.