module WeakHeaders

Provides `header_validates` DSL to controllers to validate request headers.

Examples

class AuthController < ApplicationController
  rescue_from WeakHeaders::ValidationError do |e|
    render text: e.message, status: 400
  end

  header_validates :create do
    requires 'X-Test-Token'
    optional 'X-Test-Id' do |value|
      value =~ /\A\d+\z/
    end
  end

  def create
    respond_with Auth.authenticate(token: request.headers['X-Test-Token'])
  end
end

Constants

VERSION

Public Class Methods

stats() click to toggle source
# File lib/weak_headers.rb, line 34
def self.stats
  @stats ||= ActiveSupport::HashWithIndifferentAccess.new do |hash, key|
    hash[key] = ActiveSupport::HashWithIndifferentAccess.new
  end
end