How do I set HTTP Headers in Ruby/Sinatra app, hosted on Heroku? How do I set HTTP Headers in Ruby/Sinatra app, hosted on Heroku? ruby ruby

How do I set HTTP Headers in Ruby/Sinatra app, hosted on Heroku?


Usually dynamically generated pages have no caching so the

response.headers['Cache-Control'] = 'public, max-age=300'

header is the right starting point.

Try using one of the services at "Use a Web-based service" to see if they show up in the HTTPd header sent back from your site.


You can also access the header fields of the response object with this syntax:

response['Cache-Control'] = 'public, max-age=600'


In Sinatra you can use the cache_control method:

get '/' do  # Cache for 24 hours  cache_control :public, max_age: 86400  # Your magic goes hereend