Published on Mar 28, 2018
in category programming
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')