4
votes

i want to remove some headers from (ruby on rails) response

the header response:

  • HTTP/1.1 200 OK
  • Date: Thu, 06 Jun 2013 14:42:26 GMT
  • Connection: Keep-Alive
  • X-Runtime: 0.01900
  • Content-Type: text/plain; charset=utf-8
  • Cache-Control: private, max-age=0, must-revalidate
  • Server: WEBrick/1.3.1 (Ruby/1.8.7/2012-10-12)
  • Content-Length: 281
  • Etag: "71078380e2824af40330c40e73fb9869",
  • Set-Cookie: SV_session=BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7AA%253D%253D--c93221da69cab6c6d742157e1ef03841ea4e63e8; path=/

the headers that i want to remove or change are:

  • Connection: Keep-Alive (change to closed)
  • X-Runtime: 0.01900 (remove this)
  • Cache-Control: private, max-age=0, must-revalidate (remove this)
  • Server: WEBrick/1.3.1 (Ruby/1.8.7/2012-10-12) (remove this)
  • Etag:... (remove this)
  • Set-Cookie:....(remove this)
1

1 Answers

6
votes

You can try manipulating the response in your controller directly:

response.headers['Connection'] = 'Closed'
remove_keys = %w(X-Runtime Cache-Control Server Etag Set-Cookie)
response.headers.delete_if{|key| remove_keys.include? key}