Class: ForceSslMiddleware
- Inherits:
-
Object
- Object
- ForceSslMiddleware
- Defined in:
- lib/force_ssl_middleware.rb,
lib/force_ssl_middleware/version.rb
Overview
copied from Rails github.com/rails/rails/blob/2468b161a6ada171cceeddaf418b540eb98f2d55/actionpack/lib/action_dispatch/middleware/ssl.rb#L9 Add support for excluded_paths
Constant Summary collapse
- YEAR =
31536000
- VERSION =
"0.1.0"
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ ForceSslMiddleware
constructor
A new instance of ForceSslMiddleware.
Constructor Details
#initialize(app, options = {}) ⇒ ForceSslMiddleware
Returns a new instance of ForceSslMiddleware.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/force_ssl_middleware.rb', line 10 def initialize(app, = {}) @app = app @hsts = .fetch(:hsts, {}) @hsts = {} if @hsts == true @hsts = self.class..merge(@hsts) if @hsts @host = [:host] @port = [:port] @excluded_paths = [:excluded_paths] validate_excluded_paths end |
Class Method Details
.default_hsts_options ⇒ Object
6 7 8 |
# File 'lib/force_ssl_middleware.rb', line 6 def self. { :expires => YEAR, :subdomains => false } end |
Instance Method Details
#call(env) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/force_ssl_middleware.rb', line 24 def call(env) request = ActionDispatch::Request.new(env) if excluded_path?(request.fullpath) @app.call(env) else if request.ssl? status, headers, body = @app.call(env) headers.reverse_merge!(hsts_headers) (headers) [status, headers, body] else redirect_to_https(request) end end end |