项目作者: tejasbubane

项目描述 :
Rack middleware for easily adding custom headers
高级语言: Ruby
项目地址: git://github.com/tejasbubane/rack_custom_headers.git
创建时间: 2019-01-31T12:21:00Z
项目社区:https://github.com/tejasbubane/rack_custom_headers

开源协议:

下载


rack_custom_headers

Build Status

Custom headers for your rack app.

This simple rack middleware will allow you to easily add custom headers to your request/response.

Installation

  1. gem 'rack_custom_headers'

Usage

Rails apps

In config/application.rb:

  1. config.middleware.use Rack::CustomHeaders <hash options with headername and generator proc>

eg.

  1. config.middleware.use Rack::CustomHeaders, "X-Trace-ID" => -> { SecureRandom.hex(10) }, "X-Foo" => -> :default

Refer docs for more details.

Non-Rails apps

In config.ru:

  1. use Rack::RequestID <hash options same as above>

Config

  • Headers will only be added. If header already present, it will not be overridden.

  • A config hash is mandatory to be passed in use otherwise nothing will be added.

  • Config hash should be of the format "header-name" => -> { ... } or "header-name" => :default.

  • When symbol :default is passed instead of proc, a new UUID will be generated and added.