prerender_rails 1.7.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/lib/prerender_rails.rb +28 -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: 5b30d3022d29d47b8ab191bb223c669544cf0c91b2ae47d013e36e553d90b4b1
|
4
|
+
data.tar.gz: ad84a1c0b1e4a411575b53a17e9f6aa08445e264cf1c8216738ef79975ec1dcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a41fde4e2d9372eb8a023e8fd9a56cd19944d2558da90d39caff0044aae21e0ee02ea7b3c1adaa26b0d757670e3c7f334b1b64cafb06dbe189411082646bfc21
|
7
|
+
data.tar.gz: 5b952c533002d2792f9f92c4fe21540349568fb82bcc2d23212466613321a706255b4aaae2e09b347784f4d5a1ee1fb582a83c9a96712cec14d935a99a1a371a
|
data/.travis.yml
CHANGED
data/lib/prerender_rails.rb
CHANGED
@@ -4,6 +4,19 @@ 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',
|
9
22
|
'yahoo',
|
@@ -35,7 +48,8 @@ module Rack
|
|
35
48
|
'Discordbot',
|
36
49
|
'Google Page Speed',
|
37
50
|
'Qwantify',
|
38
|
-
'Chrome-Lighthouse'
|
51
|
+
'Chrome-Lighthouse',
|
52
|
+
'TelegramBot'
|
39
53
|
]
|
40
54
|
|
41
55
|
@extensions_to_ignore = [
|
@@ -175,6 +189,19 @@ module Rack
|
|
175
189
|
response['Content-Length'] = response.body.length
|
176
190
|
response.delete('Content-Encoding')
|
177
191
|
end
|
192
|
+
|
193
|
+
hop_by_hop_headers = @hop_by_hop_headers
|
194
|
+
connection = response['Connection']
|
195
|
+
if connection
|
196
|
+
connection_hop_by_hop_headers = connection.split(',').
|
197
|
+
map(&:strip).
|
198
|
+
map(&:downcase).
|
199
|
+
difference(@connection_header_values)
|
200
|
+
hop_by_hop_headers = connection_hop_by_hop_headers.
|
201
|
+
concat(hop_by_hop_headers)
|
202
|
+
end
|
203
|
+
hop_by_hop_headers.each { |h| response.delete(h) }
|
204
|
+
|
178
205
|
response
|
179
206
|
rescue
|
180
207
|
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.8.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.8.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: 2021-11-04 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
|