Skip to content
Browse files

Add exclude option

  • Loading branch information...
1 parent 63eb0e9 commit 2e7958df52297c1beb08724f1aa37bd580552e49 @josh josh committed
Showing with 11 additions and 1 deletion.
  1. +5 −1 lib/rack/ssl.rb
  2. +6 −0 test/test_ssl.rb
View
6 lib/rack/ssl.rb
@@ -15,10 +15,14 @@ def initialize(app, options = {})
@hsts = options[:hsts]
@hsts = {} if @hsts.nil? || @hsts == true
@hsts = self.class.default_hsts_options.merge(@hsts) if @hsts
+
+ @exclude = options[:exclude]
end
def call(env)
- if scheme(env) == 'https'
+ if @exclude && @exclude.call(env)
+ @app.call(env)
+ elsif scheme(env) == 'https'
status, headers, body = @app.call(env)
headers = hsts_headers.merge(headers)
flag_cookies_as_secure!(headers)
View
6 test/test_ssl.rb
@@ -36,6 +36,12 @@ def test_redirects_http_to_https
last_response.headers['Location']
end
+ def test_exclude_from_redirect
+ self.app = Rack::SSL.new(default_app, :exclude => lambda { |env| true })
+ get "http://example.org/"
+ assert last_response.ok?
+ end
+
def test_hsts_header_by_default
get "https://example.org/"
assert_equal "max-age=31536000",

0 comments on commit 2e7958d

Please sign in to comment.
Something went wrong with that request. Please try again.