prerender_rails 1.7.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/lib/prerender_rails.rb +29 -1
- data/prerender_rails.gemspec +1 -1
- data/test/lib/prerender_rails.rb +36 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31eaea5bcb5ca7912fe4702e55d5ad48834c5c4912026b3c7c5b80e8b67c2273
|
4
|
+
data.tar.gz: b93d84f1616b9338507cbd976dcf0b0e5e2b1e8676fb9543364f606bd8df0652
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea3b84d1fa613248dace19ffee4b66ef4014b42da4c558db1e22663a5de8c7d3c8969abb84ac3ab18743155a5e5026e5b54e1b6a72f803c5917a64d98f6a7b77
|
7
|
+
data.tar.gz: d51a0feaa238dd3b88e87aa83a6388c96f06bb1d4313fa6ba2273a43e8c9b04250f5cd9523c9b5dbf9a0123eea87c9247ad3a99c3d80fb4b1a50e174488869fd
|
data/.travis.yml
CHANGED
data/lib/prerender_rails.rb
CHANGED
@@ -4,8 +4,22 @@ module Rack
|
|
4
4
|
require 'active_support'
|
5
5
|
|
6
6
|
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
|
+
|
7
20
|
@crawler_user_agents = [
|
8
21
|
'googlebot',
|
22
|
+
'Google-InspectionTool',
|
9
23
|
'yahoo',
|
10
24
|
'bingbot',
|
11
25
|
'baiduspider',
|
@@ -35,7 +49,8 @@ module Rack
|
|
35
49
|
'Discordbot',
|
36
50
|
'Google Page Speed',
|
37
51
|
'Qwantify',
|
38
|
-
'Chrome-Lighthouse'
|
52
|
+
'Chrome-Lighthouse',
|
53
|
+
'TelegramBot'
|
39
54
|
]
|
40
55
|
|
41
56
|
@extensions_to_ignore = [
|
@@ -175,6 +190,19 @@ module Rack
|
|
175
190
|
response['Content-Length'] = response.body.length
|
176
191
|
response.delete('Content-Encoding')
|
177
192
|
end
|
193
|
+
|
194
|
+
hop_by_hop_headers = @hop_by_hop_headers
|
195
|
+
connection = response['Connection']
|
196
|
+
if connection
|
197
|
+
connection_hop_by_hop_headers = connection.split(',').
|
198
|
+
map(&:strip).
|
199
|
+
map(&:downcase).
|
200
|
+
difference(@connection_header_values)
|
201
|
+
hop_by_hop_headers = connection_hop_by_hop_headers.
|
202
|
+
concat(hop_by_hop_headers)
|
203
|
+
end
|
204
|
+
hop_by_hop_headers.each { |h| response.delete(h) }
|
205
|
+
|
178
206
|
response
|
179
207
|
rescue
|
180
208
|
nil
|
data/prerender_rails.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "prerender_rails"
|
5
|
-
spec.version = "1.
|
5
|
+
spec.version = "1.9.0"
|
6
6
|
spec.authors = ["Todd Hooper"]
|
7
7
|
spec.email = ["todd@prerender.io"]
|
8
8
|
spec.description = %q{Rails middleware to prerender your javascript heavy pages on the fly by a phantomjs service}
|
data/test/lib/prerender_rails.rb
CHANGED
@@ -159,6 +159,42 @@ describe Rack::Prerender do
|
|
159
159
|
assert_equal( { 'test' => 'test2Header'}, response[1] )
|
160
160
|
end
|
161
161
|
|
162
|
+
it "should return a prerendered response stripped of hop-by-hop headers" do
|
163
|
+
request = Rack::MockRequest.env_for "/", "HTTP_USER_AGENT" => bot
|
164
|
+
stub_request(:get, @prerender.build_api_url(request)).
|
165
|
+
with(:headers => { 'User-Agent' => bot }).
|
166
|
+
to_return(:body => "<html></html>", :status => 401, :headers => {
|
167
|
+
'Content-Type' => 'text/html',
|
168
|
+
'Transfer-Encoding' => 'Chunked',
|
169
|
+
'Connection' => 'Keep-Alive',
|
170
|
+
'Keep-Alive' => 'timeout=5, max=100',
|
171
|
+
'Public' => 'GET HEAD',
|
172
|
+
'Proxy-Authenticate' => 'Basic',
|
173
|
+
'X-Drop-Test' => 'ShouldAlwaysHappen',
|
174
|
+
'Upgrade' => 'dummy'
|
175
|
+
})
|
176
|
+
response = Rack::Prerender.new(@app).call(request)
|
177
|
+
|
178
|
+
assert_equal response[2], ["<html></html>"]
|
179
|
+
assert_equal response[0], 401
|
180
|
+
assert_equal( { 'content-type' => 'text/html', 'x-drop-test' => 'ShouldAlwaysHappen'}, response[1] )
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should return a prerendered response stripped of custom-defined hop-by-hop headers" do
|
184
|
+
request = Rack::MockRequest.env_for "/", "HTTP_USER_AGENT" => bot
|
185
|
+
stub_request(:get, @prerender.build_api_url(request)).
|
186
|
+
with(:headers => { 'User-Agent' => bot }).
|
187
|
+
to_return(:body => "<html></html>", :status => 200, :headers => {
|
188
|
+
'Content-Type' => 'text/html',
|
189
|
+
'Connection' => 'Close, X-Drop-Test',
|
190
|
+
'X-Drop-Test' => 'ShouldNeverHappen'
|
191
|
+
})
|
192
|
+
response = Rack::Prerender.new(@app).call(request)
|
193
|
+
|
194
|
+
assert_equal response[2], ["<html></html>"]
|
195
|
+
assert_equal response[0], 200
|
196
|
+
assert_equal( { 'content-type' => 'text/html' }, response[1] )
|
197
|
+
end
|
162
198
|
|
163
199
|
describe '#buildApiUrl' do
|
164
200
|
it "should build the correct api url with the default url" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prerender_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Hooper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
|
-
rubygems_version: 3.1
|
120
|
+
rubygems_version: 3.0.3.1
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: Prerender your backbone/angular/javascript rendered application on the fly
|