seo_cache 1.1.1 → 1.2.2
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 -3
- data/CHANGELOG.md +16 -0
- data/README.md +2 -0
- data/lib/seo_cache/middleware.rb +11 -22
- data/lib/seo_cache/page_render.rb +8 -15
- data/lib/seo_cache/populate_cache.rb +1 -1
- data/lib/seo_cache/version.rb +1 -1
- 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: a025198e97eaad8a73126dbbdefdc559563add982f0cbeae20c56fb9f05a1ef4
|
4
|
+
data.tar.gz: 94a3dabdc94052d6830af5a32e44799485fcba7d5ef63a4e6e90b40f3dd556ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3e952a05d489b1f449ee39e343d0732e0c882829e09ec2b5cadfe430f5d34d7a924c89754d4536164d1a3d897203ef1af4a580bae576dfbdd5a516583f5a08b
|
7
|
+
data.tar.gz: c4b4fb074b52e84d88f3f5b2aef39301b84989a4b66c02d19b61f21730f81062bfce934bac21ee067b0ef8d72a700005bd72885ab78cce08a3e927985c8bf25a
|
data/.travis.yml
CHANGED
@@ -30,12 +30,12 @@ script: bundle exec rake $RAKE_TASK
|
|
30
30
|
|
31
31
|
matrix:
|
32
32
|
include:
|
33
|
-
- rvm:
|
33
|
+
- rvm: 3.0
|
34
34
|
gemfile: Gemfile
|
35
35
|
env: RAKE_TASK=spec
|
36
|
-
- rvm: 2.
|
36
|
+
- rvm: 2.7
|
37
37
|
gemfile: Gemfile
|
38
38
|
env: RAKE_TASK=spec
|
39
|
-
- rvm: 2.
|
39
|
+
- rvm: 2.6
|
40
40
|
gemfile: Gemfile
|
41
41
|
env: RAKE_TASK=spec
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
## 1.2.2
|
2
|
+
|
3
|
+
- Update Ruby version for Travis testing
|
4
|
+
|
5
|
+
## 1.2.1
|
6
|
+
|
7
|
+
- Update deprecated Selenium options
|
8
|
+
|
9
|
+
## 1.2.0
|
10
|
+
|
11
|
+
- Do not try to cache invalid requests
|
12
|
+
|
13
|
+
## 1.1.2
|
14
|
+
|
15
|
+
- Correct populate seo cache method
|
16
|
+
|
1
17
|
## 1.1.1
|
2
18
|
|
3
19
|
- Add new option to use locale as first directory for cache path
|
data/README.md
CHANGED
data/lib/seo_cache/middleware.rb
CHANGED
@@ -16,52 +16,39 @@ module SeoCache
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def call(env)
|
19
|
-
|
19
|
+
@status, @headers, @response = @app.call(env)
|
20
|
+
|
21
|
+
if prerender_page?(env, @status)
|
20
22
|
cached_response = before_render(env)
|
21
23
|
|
22
24
|
return cached_response.finish if cached_response.present?
|
23
25
|
|
24
|
-
if SeoCache.log_missed_cache
|
25
|
-
env_request = Rack::Request.new(env)
|
26
|
-
SeoCache.log("missed cache : #{env_request.path} (User agent: #{env_request.user_agent})")
|
27
|
-
end
|
28
|
-
|
29
26
|
if SeoCache.prerender_service_url.present?
|
30
27
|
prerender_response = prerender_service(env)
|
31
28
|
if prerender_response
|
32
29
|
response = build_response_from_prerender(prerender_response.body)
|
33
30
|
after_render(env, prerender_response)
|
31
|
+
|
34
32
|
return response.finish
|
35
33
|
end
|
36
34
|
else
|
37
35
|
Thread.new do
|
38
36
|
prerender_data = page_render(env)
|
39
|
-
# Extract status from render page or return success (200)
|
40
|
-
status = prerender_data&.scan(/<!--status:(\d+)-->/)&.last&.first || 200
|
41
|
-
|
42
|
-
if SeoCache.log_missed_cache && status.to_s.start_with?('2')
|
43
|
-
env_request = Rack::Request.new(env)
|
44
|
-
SeoCache.log("missed cache : #{env_request.path} (User agent: #{env_request.user_agent})")
|
45
|
-
end
|
46
37
|
|
47
|
-
after_render(env, prerender_data, status)
|
38
|
+
after_render(env, prerender_data, @status)
|
48
39
|
end
|
49
40
|
end
|
50
41
|
elsif prerender_params?(env)
|
51
|
-
env['seo_mode']
|
52
|
-
# Add status to render page because Selenium doesn't return http headers or status...
|
42
|
+
env['seo_mode'] = true
|
53
43
|
status, headers, response = @app.call(env)
|
54
|
-
status_code = "<!--status:#{status}-->"
|
55
|
-
# Cannot add at the top of file, Chrome removes leading comments...
|
56
44
|
begin
|
57
|
-
|
58
|
-
return [status, headers, [body_code]]
|
45
|
+
return [status, headers, [response.body]]
|
59
46
|
rescue
|
60
47
|
return [status, headers, [nil]]
|
61
48
|
end
|
62
49
|
end
|
63
50
|
|
64
|
-
return @
|
51
|
+
return [@status, @headers, @response]
|
65
52
|
end
|
66
53
|
|
67
54
|
def prerender_params?(env)
|
@@ -75,13 +62,15 @@ module SeoCache
|
|
75
62
|
return true if query_params.has_key?(SeoCache.prerender_url_param) || query_params.has_key?(SeoCache.force_cache_url_param)
|
76
63
|
end
|
77
64
|
|
78
|
-
def prerender_page?(env)
|
65
|
+
def prerender_page?(env, status)
|
79
66
|
user_agent = env['HTTP_USER_AGENT']
|
80
67
|
buffer_agent = env['HTTP_X_BUFFERBOT']
|
81
68
|
is_requesting_prerender_page = false
|
82
69
|
|
83
70
|
return false unless user_agent
|
84
71
|
|
72
|
+
return false if status.to_i > 299
|
73
|
+
|
85
74
|
return false if env['REQUEST_METHOD'] != 'GET'
|
86
75
|
|
87
76
|
request = Rack::Request.new(env)
|
@@ -33,21 +33,14 @@ module SeoCache
|
|
33
33
|
|
34
34
|
Selenium::WebDriver::Chrome.path = SeoCache.chrome_path if SeoCache.chrome_path
|
35
35
|
|
36
|
-
browser_options =
|
37
|
-
browser_options
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
browser_options.args << '--disable-extensions'
|
45
|
-
browser_options.args << '--disable-logging'
|
46
|
-
browser_options.args << '--disable-notifications'
|
47
|
-
browser_options.args << '--disable-sync'
|
48
|
-
browser_options.args << '--window-size=1920x1080'
|
49
|
-
browser_options.args << "--remote-debugging-port=#{SeoCache.chrome_debugging_port}" if SeoCache.chrome_debugging_port
|
50
|
-
@driver = ::Selenium::WebDriver.for(:chrome, options: browser_options)
|
36
|
+
browser_options = %w[headless incognito disable-gpu disable-infobars disable-dev-shm-usage disable-gpu disable-web-security disable-extensions no-sandbox disable-logging disable-notifications disable-sync window-size=1920x1080]
|
37
|
+
browser_options << "remote-debugging-port=#{SeoCache.chrome_debugging_port}" if SeoCache.chrome_debugging_port
|
38
|
+
@driver = ::Selenium::WebDriver.for(
|
39
|
+
:chrome,
|
40
|
+
capabilities: [Selenium::WebDriver::Chrome::Options.new(
|
41
|
+
args: browser_options
|
42
|
+
)]
|
43
|
+
)
|
51
44
|
end
|
52
45
|
end
|
53
46
|
end
|
@@ -35,7 +35,7 @@ module SeoCache
|
|
35
35
|
private
|
36
36
|
|
37
37
|
def generate_cache(path, locale_domain = nil)
|
38
|
-
return if @page_caching.cache_exists?(path,
|
38
|
+
return if @page_caching.cache_exists?(path, locale_domain) && !@force_cache
|
39
39
|
|
40
40
|
url = @host + path
|
41
41
|
url += path.include?('?') ? '&' : '?'
|
data/lib/seo_cache/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seo_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FloXcoder
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -229,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
229
229
|
- !ruby/object:Gem::Version
|
230
230
|
version: '0'
|
231
231
|
requirements: []
|
232
|
-
rubygems_version: 3.
|
232
|
+
rubygems_version: 3.3.5
|
233
233
|
signing_key:
|
234
234
|
specification_version: 4
|
235
235
|
summary: Cache dedicated for SEO with Javascript rendering
|