4

我想从(Ruby on Rails)响应中删除一些标头。

标头响应:

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=/

我要删除或更改的标题是:

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)
4

1 回答 1

6

您可以尝试直接在控制器中操作响应:

response.headers['Connection'] = 'Closed'
remove_keys = %w(X-Runtime Cache-Control Server Etag Set-Cookie)
response.headers.delete_if{|key| remove_keys.include? key}
于 2013-06-06T16:47:09.743 回答