Testing with Rack-test custom headers

When writing a method that requires a custom request header, ie. “X-Api-Key”, use the following:

  key = request.headers['HTTP_X_API_KEY']

Instead of

  key = request.headers['X-Api-Key']

This is because Rack converts all custom headers into the HTTP_ format.

When writing your tests, remember to specify like the following

  get '/test', {}, {"HTTP_X_API_KEY" => "key"}

Even though when in your actual query, you’re sending the header as X-Api-Key