提交 7b75b678 编写于 作者: R Rafael Mendonça França

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

Avoid URI parsing
...@@ -32,11 +32,14 @@ def call(env) ...@@ -32,11 +32,14 @@ def call(env)
private private
def redirect_to_https(request) def redirect_to_https(request)
url = URI(request.url) host = @host || request.host
url.scheme = "https" port = @port || request.port
url.host = @host if @host
url.port = @port if @port location = "https://#{host}"
headers = { 'Content-Type' => 'text/html', 'Location' => url.to_s } location << ":#{port}" if port != 80
location << request.fullpath
headers = { 'Content-Type' => 'text/html', 'Location' => location }
[301, headers, []] [301, headers, []]
end end
......
...@@ -196,6 +196,13 @@ def test_redirect_to_host_and_port ...@@ -196,6 +196,13 @@ def test_redirect_to_host_and_port
response.headers['Location'] response.headers['Location']
end 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 def test_redirect_to_secure_host_when_on_subdomain
self.app = ActionDispatch::SSL.new(default_app, :host => "ssl.example.org") self.app = ActionDispatch::SSL.new(default_app, :host => "ssl.example.org")
get "http://ssl.example.org/path?key=value" get "http://ssl.example.org/path?key=value"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册