prerender_rails 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e710c94d4517957a7198a878b74edb3d2ce599a
4
- data.tar.gz: 3d61079a206b75b6ebf47d2acd64ed1774fa1b25
3
+ metadata.gz: f5013e7eaea9bbf3be69499894144a70bf904911
4
+ data.tar.gz: a25e41c1f16f935222447687ff1e85f49e357f34
5
5
  SHA512:
6
- metadata.gz: e2f1fd70277c97905a06b2e674ca4e882aea82700c8abdc65eb65e6b4f2a016392f1bb97482bcd8e7fc87269f26ef51ced69b8cdfb2e937abff8b85c209c9abe
7
- data.tar.gz: d5f453676bf4373c2c6634713684ccd938ca1761cea76518ec29aff5b2f3a5ce5567fc8083befa2df2d6afe31dd8ba78c7f6191f1319df06246d548d415373b4
6
+ metadata.gz: 4e4005a4509b94bda2ec6783f7b0a2ba5bc6c3203257cb5cb57cbda056c5c52a92f6e0758fcc252eb8fbf0fab5016a2725d0aa29bccafd2518f4ded7954a72bd
7
+ data.tar.gz: 85ce4274d97f7148160fdba543e7c8c3784d47e48f7c2183d9d040e4b08593158802d8d6c2d5fd2b31b64b1773bf5a41b04c4842d44761e70459c4ed5c04bd5c
data/README.md CHANGED
@@ -28,22 +28,22 @@ And in `config/environment/production.rb`, add this line:
28
28
 
29
29
  ### Whitelist
30
30
 
31
- Whitelist a single url path or multiple url paths. If a whitelist is supplied, only url's containing a whitelist path will be prerendered.
31
+ Whitelist a single url path or multiple url paths. Compares using regex, so be specific when possible. If a whitelist is supplied, only url's containing a whitelist path will be prerendered.
32
32
  ```ruby
33
- config.middleware.use Rack::Prerender, whitelist: '/search/tto'
33
+ config.middleware.use Rack::Prerender, whitelist: '^/search'
34
34
  ```
35
35
  ```ruby
36
- config.middleware.use Rack::Prerender, whitelist: ['/search', '/profile']
36
+ config.middleware.use Rack::Prerender, whitelist: ['/search', '/users/.*/profile']
37
37
  ```
38
38
 
39
39
  ### Blacklist
40
40
 
41
- Blacklist a single url path or multiple url paths. If a blacklist is supplied, all url's will be prerendered except ones containing a blacklist path.
41
+ Blacklist a single url path or multiple url paths. Compares using regex, so be specific when possible. If a blacklist is supplied, all url's will be prerendered except ones containing a blacklist path.
42
42
  ```ruby
43
- config.middleware.use Rack::Prerender, blacklist: '/search/tto'
43
+ config.middleware.use Rack::Prerender, blacklist: '^/search'
44
44
  ```
45
45
  ```ruby
46
- config.middleware.use Rack::Prerender, blacklist: ['/search', '/profile']
46
+ config.middleware.use Rack::Prerender, blacklist: ['/search', '/users/.*/profile']
47
47
  ```
48
48
 
49
49
  ### Using your own prerender service
@@ -55,15 +55,16 @@ module Rack
55
55
  return false if @extensions_to_ignore.any? { |extension| request.path.include? extension }
56
56
 
57
57
  #if it is a bot and not requesting a resource and is not whitelisted...dont prerender
58
- return false if @options[:whitelist].is_a?(Array) && @options[:whitelist].all? { |whitelisted| !request.path.include? whitelisted }
58
+ return false if @options[:whitelist].is_a?(Array) && @options[:whitelist].all? { |whitelisted| !!Regexp.new(whitelisted).match(request.path) }
59
59
 
60
60
  #if it is a bot and not requesting a resource and is not blacklisted(url or referer)...dont prerender
61
61
  if @options[:blacklist].is_a?(Array) && @options[:blacklist].any? { |blacklisted|
62
62
  blacklistedUrl = false
63
63
  blacklistedReferer = false
64
+ regex = Regexp.new(blacklisted)
64
65
 
65
- blacklistedUrl = request.path.include? blacklisted
66
- blacklistedReferer = request.referer.include? blacklisted if request.referer
66
+ blacklistedUrl = !!regex.match(request.path)
67
+ blacklistedReferer = !!regex.match(request.referer) if request.referer
67
68
 
68
69
  blacklistedUrl || blacklistedReferer
69
70
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "prerender_rails"
5
- spec.version = "0.0.3"
5
+ spec.version = "0.0.4"
6
6
  spec.authors = ["Todd Hooper"]
7
7
  spec.email = ["todd@collectiveip.com"]
8
8
  spec.description = %q{Rails middleware to prerender your javascript heavy pages on the fly by a phantomjs service}
@@ -42,6 +42,13 @@ describe Rack::Prerender do
42
42
  assert_equal response[2], ""
43
43
  end
44
44
 
45
+ it "should continue to app routes if the url is not part of the regex specific whitelist" do
46
+ request = Rack::MockRequest.env_for "/saved/search/blah", "HTTP_USER_AGENT" => bot
47
+ response = Rack::Prerender.new(@app, whitelist: ['/search', '/help']).call(request)
48
+
49
+ assert_equal response[2], ""
50
+ end
51
+
45
52
  it "should return a prerendered response if the url is part of the whitelist" do
46
53
  request = Rack::MockRequest.env_for "/search/things?query=blah", "HTTP_USER_AGENT" => bot
47
54
  stub_request(:get, @prerender.build_api_url(request)).to_return(:body => "<html></html>")
@@ -50,6 +57,14 @@ describe Rack::Prerender do
50
57
  assert_equal response[2].body, ["<html></html>"]
51
58
  end
52
59
 
60
+ it "should return a prerendered response if the url is part of the regex specific whitelist" do
61
+ request = Rack::MockRequest.env_for "/search/things?query=blah", "HTTP_USER_AGENT" => bot
62
+ stub_request(:get, @prerender.build_api_url(request)).to_return(:body => "<html></html>")
63
+ response = Rack::Prerender.new(@app, whitelist: ['^/search.*query', '/help']).call(request)
64
+
65
+ assert_equal response[2].body, ["<html></html>"]
66
+ end
67
+
53
68
  it "should continue to app routes if the url is part of the blacklist" do
54
69
  request = Rack::MockRequest.env_for "/search/things?query=blah", "HTTP_USER_AGENT" => bot
55
70
  response = Rack::Prerender.new(@app, blacklist: ['/search', '/help']).call(request)
@@ -57,6 +72,13 @@ describe Rack::Prerender do
57
72
  assert_equal response[2], ""
58
73
  end
59
74
 
75
+ it "should continue to app routes if the url is part of the regex specific blacklist" do
76
+ request = Rack::MockRequest.env_for "/search/things?query=blah", "HTTP_USER_AGENT" => bot
77
+ response = Rack::Prerender.new(@app, blacklist: ['^/search', '/help']).call(request)
78
+
79
+ assert_equal response[2], ""
80
+ end
81
+
60
82
  it "should return a prerendered response if the url is not part of the blacklist" do
61
83
  request = Rack::MockRequest.env_for "/profile/blah", "HTTP_USER_AGENT" => bot
62
84
  stub_request(:get, @prerender.build_api_url(request)).to_return(:body => "<html></html>")
@@ -65,6 +87,14 @@ describe Rack::Prerender do
65
87
  assert_equal response[2].body, ["<html></html>"]
66
88
  end
67
89
 
90
+ it "should return a prerendered response if the url is not part of the regex specific blacklist" do
91
+ request = Rack::MockRequest.env_for "/profile/search/blah", "HTTP_USER_AGENT" => bot
92
+ stub_request(:get, @prerender.build_api_url(request)).to_return(:body => "<html></html>")
93
+ response = Rack::Prerender.new(@app, blacklist: ['^/search', '/help']).call(request)
94
+
95
+ assert_equal response[2].body, ["<html></html>"]
96
+ end
97
+
68
98
  it "should continue to app routes if the referer is part of the blacklist" do
69
99
  request = Rack::MockRequest.env_for "/api/results", "HTTP_USER_AGENT" => bot, "HTTP_REFERER" => '/search'
70
100
  response = Rack::Prerender.new(@app, blacklist: ['/search', '/help']).call(request)
@@ -72,6 +102,13 @@ describe Rack::Prerender do
72
102
  assert_equal response[2], ""
73
103
  end
74
104
 
105
+ it "should continue to app routes if the referer is part of the regex specific blacklist" do
106
+ request = Rack::MockRequest.env_for "/api/results", "HTTP_USER_AGENT" => bot, "HTTP_REFERER" => '/search'
107
+ response = Rack::Prerender.new(@app, blacklist: ['^/search', '/help']).call(request)
108
+
109
+ assert_equal response[2], ""
110
+ end
111
+
75
112
  it "should return a prerendered response if the referer is not part of the blacklist" do
76
113
  request = Rack::MockRequest.env_for "/api/results", "HTTP_USER_AGENT" => bot, "HTTP_REFERER" => '/search'
77
114
  stub_request(:get, @prerender.build_api_url(request)).to_return(:body => "<html></html>")
@@ -79,6 +116,14 @@ describe Rack::Prerender do
79
116
 
80
117
  assert_equal response[2].body, ["<html></html>"]
81
118
  end
119
+
120
+ it "should return a prerendered response if the referer is not part of the regex specific blacklist" do
121
+ request = Rack::MockRequest.env_for "/api/results", "HTTP_USER_AGENT" => bot, "HTTP_REFERER" => '/profile/search'
122
+ stub_request(:get, @prerender.build_api_url(request)).to_return(:body => "<html></html>")
123
+ response = Rack::Prerender.new(@app, blacklist: ['^/search', '/help']).call(request)
124
+
125
+ assert_equal response[2].body, ["<html></html>"]
126
+ end
82
127
 
83
128
  describe '#buildApiUrl' do
84
129
  it "should build the correct api url with the default url" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prerender_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Hooper