https://github.com/tejasbubane/rack_custom_headers
Rack middleware for easily adding custom headers
https://github.com/tejasbubane/rack_custom_headers
rack-middleware rails ruby
Last synced: 12 days ago
JSON representation
Rack middleware for easily adding custom headers
- Host: GitHub
- URL: https://github.com/tejasbubane/rack_custom_headers
- Owner: tejasbubane
- Created: 2019-01-31T12:21:00.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-11T07:53:48.000Z (over 7 years ago)
- Last Synced: 2025-03-25T09:51:26.327Z (about 1 year ago)
- Topics: rack-middleware, rails, ruby
- Language: Ruby
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rack_custom_headers
[](https://travis-ci.org/tejasbubane/rack_custom_headers)
Custom headers for your rack app.
This simple rack middleware will allow you to easily add custom headers to your request/response.
## Installation
```ruby
gem 'rack_custom_headers'
```
## Usage
#### Rails apps
In `config/application.rb`:
```
config.middleware.use Rack::CustomHeaders
```
eg.
```ruby
config.middleware.use Rack::CustomHeaders, "X-Trace-ID" => -> { SecureRandom.hex(10) }, "X-Foo" => -> :default
```
Refer [docs](https://guides.rubyonrails.org/rails_on_rack.html#configuring-middleware-stack) for more details.
#### Non-Rails apps
In `config.ru`:
```ruby
use Rack::RequestID
```
### 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.