Skip to content

Commit

Permalink
Merge pull request #7 from bartt/master
Browse files Browse the repository at this point in the history
Also allow the SSL port to be specified
  • Loading branch information
josh committed Jun 10, 2011
2 parents 239e2d4 + 40c1fcb commit 6a6c15d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rack/ssl.rb
Expand Up @@ -18,6 +18,7 @@ def initialize(app, options = {})


@exclude = options[:exclude] @exclude = options[:exclude]
@host = options[:host] @host = options[:host]
@port = options[:port]
end end


def call(env) def call(env)
Expand Down Expand Up @@ -50,6 +51,7 @@ def redirect_to_https(env)
url = URI(req.url) url = URI(req.url)
url.scheme = "https" url.scheme = "https"
url.host = @host if @host url.host = @host if @host
url.port = @port if @port
headers = hsts_headers.merge('Content-Type' => 'text/html', headers = hsts_headers.merge('Content-Type' => 'text/html',
'Location' => url.to_s) 'Location' => url.to_s)


Expand Down
14 changes: 14 additions & 0 deletions test/test_ssl.rb
Expand Up @@ -124,6 +124,20 @@ def test_redirect_to_host
last_response.headers['Location'] last_response.headers['Location']
end end


def test_redirect_to_port
self.app = Rack::SSL.new(default_app, :port => 8443)
get "http://example.org/path?key=value"
assert_equal "https://example.org:8443/path?key=value",
last_response.headers['Location']
end

def test_redirect_to_host_and_port
self.app = Rack::SSL.new(default_app, :host => "ssl.example.org", :port => 8443)
get "http://example.org/path?key=value"
assert_equal "https://ssl.example.org:8443/path?key=value",
last_response.headers['Location']
end

def test_redirect_to_secure_host_when_on_subdomain def test_redirect_to_secure_host_when_on_subdomain
self.app = Rack::SSL.new(default_app, :host => "ssl.example.org") self.app = Rack::SSL.new(default_app, :host => "ssl.example.org")
get "http://ssl.example.org/path?key=value" get "http://ssl.example.org/path?key=value"
Expand Down

0 comments on commit 6a6c15d

Please sign in to comment.