An open API service indexing awesome lists of open source software.

https://github.com/kenchan0130/weak_headers

Validates request.headers in your rails controller
https://github.com/kenchan0130/weak_headers

actioncontroller rails rails5 ruby

Last synced: 5 months ago
JSON representation

Validates request.headers in your rails controller

Awesome Lists containing this project

README

          

![Build Status](https://api.travis-ci.org/kenchan0130/weak_headers.png)

# WeakHeaders
Validates `request.headers` in your rails controller.

## Installation
```ruby
gem 'weak_headers'
```

## Usage
```ruby
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
- [weak_parameters](https://github.com/r7kamura/weak_parameters)