seo_cache 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/seo_cache/middleware.rb +11 -22
- 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: 257a485a274532a58693567428f24615cf4f1c4ad9f45546d81b6ed26b2352c2
|
4
|
+
data.tar.gz: 6fe1ac814ab110ab97aca70682cdf4cff66cebc3449b6abd14594417bd26876d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5d651a0568691b994fdd94d76c52a8b6c83907e91dd8e95edcdf380cca1e994a7929e0ac92b94a0658be46f4564e33367bc6413c657fc9bcd372062362e922a
|
7
|
+
data.tar.gz: cbdbc8ba5ced409d94ddd0fed596c768042a32b1fd9ae861d2e0d2f5c406a51b447856a1005a9eded8b6ede343eeeac8acf9b6914fd4278688819d170b093204
|
data/CHANGELOG.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)
|
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.0
|
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
|