Published on Mar 27, 2018
at category how-to
If you need to add a custom HTTP header in your responses in a Ruby on Rails application, all you have to do is to add the following:
response.headers['<header name>'] = '<header value>'
either in a specific action or inside a filter of your application controller depending on whether you need this to be added in a specific or to all of your responses.
response.headers['CUSTOM'] = 'CUSTOM VALUE'
From Rails 5 and on, you can also use the following:
response.set_header('HEADER NAME', 'HEADER VALUE')