Sha256: 8d4ca09bc3a1e22773daa142615826c9ab2ef86b3cc0aa314dcb51d8c1fb1359

Contents?: true

Size: 732 Bytes

Versions: 1

Compression:

Stored size: 732 Bytes

Contents

module Rack
  module Contrib
    class Nonce
      VERSION = '0.0.2'

      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.gsub(/-/, '_')
      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.2 lib/rack/contrib/nonce.rb