Module: WeakHeaders

Defined in:
lib/weak_headers.rb,
lib/weak_headers/version.rb,
lib/weak_headers/validator.rb,
lib/weak_headers/controller.rb,
lib/weak_headers/base_validator.rb,
lib/weak_headers/validation_error.rb,
lib/weak_headers/optional_validator.rb,
lib/weak_headers/requires_validator.rb

Overview

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

Defined Under Namespace

Modules: Controller Classes: BaseValidator, OptionalValidator, Railties, RequiresValidator, ValidationError, Validator

Constant Summary collapse

VERSION =
'0.3.0'

Class Method Summary collapse

Class Method Details

.statsObject



34
35
36
37
38
# File 'lib/weak_headers.rb', line 34

def self.stats
  @stats ||= ActiveSupport::HashWithIndifferentAccess.new do |hash, key|
    hash[key] = ActiveSupport::HashWithIndifferentAccess.new
  end
end