0.0
No commit activity in last 3 years
No release in over 3 years
Add a validation headers filter to your rails controller.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
>= 0

Runtime

>= 4.0.0
 Project Readme

Build Status

WeakHeaders

Validates request.headers in your rails controller.

Installation

gem 'weak_headers'

Usage

class ApplicationController < ActionController::Base
  protect_from_forgery

  rescue_from WeakHeaders::ValidationError do |e|
    render json: { message: e.message }, status: 400
  end
end

# WeakHeaders provides `header_validates` class method to define validations.
class AuthController < ApplicationController
  header_validates :create do
    requires 'X-App-Client-Id', except: ["token", "123456"]
    optional :'X-App-Id', only: '1'
    requires 'X-App-Client-Secret' do |value|
      value =~ /\A\w{64}\z/
    end
  end

  def create
    auth = Application.authenticate(uid: request.headers['X-App-Client-Id'], secret: request.headers['X-App-Client-Secret'])
    render json: { token: auth.token }
  end
end

Available validators

  • requires
  • optional

Available options

  • only
  • except
  • handler

Inspired By