Class: Rack::Contrib::Nonce
- Inherits:
-
Object
- Object
- Rack::Contrib::Nonce
- Defined in:
- lib/rack/contrib/nonce.rb
Constant Summary collapse
- VERSION =
'0.0.2'
Instance Method Summary collapse
- #call(env) ⇒ Object
- #header_name ⇒ Object
-
#initialize(app, opts) ⇒ Nonce
constructor
A new instance of Nonce.
Constructor Details
#initialize(app, opts) ⇒ Nonce
Returns a new instance of Nonce.
6 7 8 9 10 11 |
# File 'lib/rack/contrib/nonce.rb', line 6 def initialize app, opts @app = app @logger = opts[:logger] || Logger.new('/dev/null') @seen = opts[:seen] || [] @header = opts[:header] || 'Nonce' end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rack/contrib/nonce.rb', line 17 def call env unless env[header_name] @logger.error "Denied: #{@header} not present." return [401, {}, []] end if @seen.include? env[header_name] @logger.error "Denied: #{@header} not unique." return [401, {}, []] end @seen << env[header_name] @app.call(env) end |
#header_name ⇒ Object
13 14 15 |
# File 'lib/rack/contrib/nonce.rb', line 13 def header_name 'HTTP_' + @header.upcase.gsub(/-/, '_') end |