如何从响应中删除一些头部信息。

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接