Class: Rack::HttpEnforcer

Inherits:
Object
  • Object
show all
Defined in:
lib/rack-http-enforcer.rb

Instance Method Summary collapse

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, options = {} )
  @app, @options = app, options
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