Leoh
Leoh

Reputation: 670

How to remove some headers from response

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)

Upvotes: 4

Views: 7485

Answers (1)

PinnyM
PinnyM

Reputation: 35533

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}

Upvotes: 6

Related Questions