Class: Rack::HttpEnforcer
- Inherits:
-
Object
- Object
- Rack::HttpEnforcer
- Defined in:
- lib/rack-http-enforcer.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ HttpEnforcer
constructor
A new instance of HttpEnforcer.
Constructor Details
#initialize(app, options = {}) ⇒ HttpEnforcer
Returns a new instance of HttpEnforcer.
4 5 6 |
# File 'lib/rack-http-enforcer.rb', line 4 def initialize( app, = {} ) @app, @options = app, end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rack-http-enforcer.rb', line 8 def call( env ) scheme = 'http' unless http_request?( env ) if scheme location = redirect_to || request_url( env, scheme ) body = "<html><body>You are being <a href=\"#{location}\">redirected</a>.</body></html>" [ 301, { 'Content-Type' => 'text/html', 'Location' => location }, [body] ] else @app.call( env ) end end |