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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1020870d044657759ac90591559df5abb82b9418ec242f6af3a8d100e457f593
4
- data.tar.gz: 4627cb1b8e6ee8d0429c0d3ad61151670e85f881e6c0bc117ef67b2a08dfc1d8
3
+ metadata.gz: 257a485a274532a58693567428f24615cf4f1c4ad9f45546d81b6ed26b2352c2
4
+ data.tar.gz: 6fe1ac814ab110ab97aca70682cdf4cff66cebc3449b6abd14594417bd26876d
5
5
  SHA512:
6
- metadata.gz: 0ea43ce22d924cfc142ffbcd6fc2d55989b46707c17a2fc210b5a1a31bbe6d9368c34990885a1bc476bc674145734f924fe006dad55cd2997f9a54747d4a1471
7
- data.tar.gz: 61b1a6b1502c74cf0dff847ac8912018b47e9a295bc441d10c7641e3f31762e65186539477095cac2ec8f644d9d1d5f256b55c42d3526a4aff3c30633814a18a
6
+ metadata.gz: a5d651a0568691b994fdd94d76c52a8b6c83907e91dd8e95edcdf380cca1e994a7929e0ac92b94a0658be46f4564e33367bc6413c657fc9bcd372062362e922a
7
+ data.tar.gz: cbdbc8ba5ced409d94ddd0fed596c768042a32b1fd9ae861d2e0d2f5c406a51b447856a1005a9eded8b6ede343eeeac8acf9b6914fd4278688819d170b093204
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## 1.1.2
2
2
 
3
+ - Do not try to cache invalid requests
4
+
5
+ ## 1.1.2
6
+
3
7
  - Correct populate seo cache method
4
8
 
5
9
  ## 1.1.1
@@ -16,52 +16,39 @@ module SeoCache
16
16
  end
17
17
 
18
18
  def call(env)
19
- if prerender_page?(env)
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'] = true
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
- body_code = response.body.sub(/<head( ?)(.*?)>/i, "<head\\1\\2>#{status_code}")
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 @app.call(env)
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)
@@ -1,3 +1,3 @@
1
1
  module SeoCache
2
- VERSION = '1.1.2'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
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.1.2
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: 2021-10-29 00:00:00.000000000 Z
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.2.30
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