Skip to content

Commit

Permalink
Add exclude option
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Nov 8, 2010
1 parent 63eb0e9 commit 2e7958d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rack/ssl.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ def initialize(app, options = {})
@hsts = options[:hsts] @hsts = options[:hsts]
@hsts = {} if @hsts.nil? || @hsts == true @hsts = {} if @hsts.nil? || @hsts == true
@hsts = self.class.default_hsts_options.merge(@hsts) if @hsts @hsts = self.class.default_hsts_options.merge(@hsts) if @hsts

@exclude = options[:exclude]
end end


def call(env) 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) status, headers, body = @app.call(env)
headers = hsts_headers.merge(headers) headers = hsts_headers.merge(headers)
flag_cookies_as_secure!(headers) flag_cookies_as_secure!(headers)
Expand Down
6 changes: 6 additions & 0 deletions test/test_ssl.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def test_redirects_http_to_https
last_response.headers['Location'] last_response.headers['Location']
end 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 def test_hsts_header_by_default
get "https://example.org/" get "https://example.org/"
assert_equal "max-age=31536000", assert_equal "max-age=31536000",
Expand Down

0 comments on commit 2e7958d

Please sign in to comment.