module Rack module Contrib class Nonce VERSION = '0.0.1' def initialize app, opts @app = app @logger = opts[:logger] || Logger.new('/dev/null') @seen = opts[:seen] || [] @header = opts[:header] || 'Nonce' end def header_name 'HTTP_' + @header.upcase end 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 end end end