Sha256: 1702297b83fd8fb9d761ad9946005274487f0f2db0826d9cba9857f5655e82e7

Contents?: true

Size: 715 Bytes

Versions: 1

Compression:

Stored size: 715 Bytes

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-contrib-nonce-0.0.1 lib/rack/contrib/nonce.rb