Skip to content

Commit 38c50cf

Browse files
committed
Discard hop-by-hop headers
1 parent bcfd081 commit 38c50cf

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lib/prerender_rails.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ class Prerender
44
require 'active_support'
55

66
def initialize(app, options={})
7+
@connection_header_values = [
8+
'close',
9+
'keep-alive'
10+
].freeze
11+
@hop_by_hop_headers = [
12+
'Connection',
13+
'Keep-Alive',
14+
'Public',
15+
'Proxy-Authenticate',
16+
'Transfer-Encoding',
17+
'Upgrade'
18+
].freeze
19+
720
@crawler_user_agents = [
821
'googlebot',
922
'yahoo',
@@ -175,6 +188,19 @@ def get_prerendered_page_response(env)
175188
response['Content-Length'] = response.body.length
176189
response.delete('Content-Encoding')
177190
end
191+
192+
hop_by_hop_headers = @hop_by_hop_headers
193+
connection = response['Connection']
194+
if connection
195+
connection_hop_by_hop_headers = connection.split(',').
196+
map(&:strip).
197+
map(&:downcase).
198+
difference(@connection_header_values)
199+
hop_by_hop_headers = connection_hop_by_hop_headers.
200+
concat(hop_by_hop_headers)
201+
end
202+
hop_by_hop_headers.each { |h| response.delete(h) }
203+
178204
response
179205
rescue
180206
nil

0 commit comments

Comments
 (0)