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

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

Awesome Lists containing this project

README

          

# rack_custom_headers

[![Build Status](https://travis-ci.org/tejasbubane/rack_custom_headers.svg?branch=master)](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.