prerender_rails 0.0.7 → 0.0.8

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: 0aa07c3cf94a8d7a3b60c3e68271d4cbb59f3e03
4
- data.tar.gz: 31492b9262dc21a6a8691234aff195ba58311a0e
3
+ metadata.gz: 59948717e824a0f84b73f6a8f3b5c1a3cadb294d
4
+ data.tar.gz: 811bc0d1154cadc3a8ad64fa3ea94bb6db48f2bc
5
5
  SHA512:
6
- metadata.gz: ccbda2e52bd731646b3dc8173fda1ed86e319c8591a8893bd1f896bd6bfc21bc54fe8e5175e03bf10a8c2bd6cd48db5091a7d3f32ce42d03ad966eca5a4b481a
7
- data.tar.gz: 97e8ea361e1228a3f2bb56d0de5aba0cc9a7fbc5bd8bcc6573eba315d43c64f940c63ef78973a199f72eca5264fba8e90a5b1837c7cf4df350220099941d23d5
6
+ metadata.gz: 3860c469fdb0f557d85ca341c4869bc47d86da0942a5690ddeced8c3e9e8be4930689f602d5190bcf71a3a24e0e41eefcbb4013e83e77155d7f736ff5b78270c
7
+ data.tar.gz: 5912a78bd5e7099ff969c49b93c4bdf44c038b6ab05fb8942fdee21cd69c79c3f48950b22df9c867842299d418193860c6d07ef417269f6670943c5044728010
@@ -3,10 +3,13 @@ module Rack
3
3
  require 'net/http'
4
4
 
5
5
  def initialize(app, options={})
6
+ # googlebot, yahoo, and bingbot are not in this list because
7
+ # we support _escaped_fragment_ instead of checking user
8
+ # agent for those crawlers
6
9
  @crawler_user_agents = [
7
- 'googlebot',
8
- 'yahoo',
9
- 'bingbot',
10
+ # 'googlebot',
11
+ # 'yahoo',
12
+ # 'bingbot',
10
13
  'baiduspider',
11
14
  'facebookexternalhit'
12
15
  ]
@@ -75,6 +78,8 @@ module Rack
75
78
 
76
79
  request = Rack::Request.new(env)
77
80
 
81
+ return true if request.query_string.include? '_escaped_fragment_'
82
+
78
83
  #if it is not a bot...dont prerender
79
84
  return false if @crawler_user_agents.all? { |crawler_user_agent| !user_agent.downcase.include?(crawler_user_agent.downcase) }
80
85
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "prerender_rails"
5
- spec.version = "0.0.7"
5
+ spec.version = "0.0.8"
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}
@@ -2,7 +2,7 @@ require_relative '../test_helper'
2
2
 
3
3
  describe Rack::Prerender do
4
4
 
5
- bot = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
5
+ bot = 'Baiduspider+(+http://www.baidu.com/search/spider.htm)'
6
6
  user = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36'
7
7
 
8
8
  before :each do
@@ -21,6 +21,14 @@ describe Rack::Prerender do
21
21
  assert_equal response[2].body, ["<html></html>"]
22
22
  end
23
23
 
24
+ it "should return a prerendered reponse if user is a bot by checking for _escaped_fragment_" do
25
+ request = Rack::MockRequest.env_for "/path?_escaped_fragment_=yes", "HTTP_USER_AGENT" => user
26
+ stub_request(:get, @prerender.build_api_url(request)).to_return(:body => "<html></html>")
27
+ response = Rack::Prerender.new(@app).call(request)
28
+
29
+ assert_equal response[2].body, ["<html></html>"]
30
+ end
31
+
24
32
  it "should continue to app routes if user is not a bot by checking agent string" do
25
33
  request = Rack::MockRequest.env_for "/", "HTTP_USER_AGENT" => user
26
34
  response = Rack::Prerender.new(@app).call(request)
@@ -35,13 +43,6 @@ describe Rack::Prerender do
35
43
  assert_equal response[2], ""
36
44
  end
37
45
 
38
- it "should continue to app routes if the url is not part of the whitelist" do
39
- request = Rack::MockRequest.env_for "/profile/blah", "HTTP_USER_AGENT" => bot
40
- response = Rack::Prerender.new(@app, whitelist: ['/search', '/help']).call(request)
41
-
42
- assert_equal response[2], ""
43
- end
44
-
45
46
  it "should continue to app routes if the url is not part of the regex specific whitelist" do
46
47
  request = Rack::MockRequest.env_for "/saved/search/blah", "HTTP_USER_AGENT" => bot
47
48
  response = Rack::Prerender.new(@app, whitelist: ['^/search', '/help']).call(request)
@@ -49,14 +50,6 @@ describe Rack::Prerender do
49
50
  assert_equal response[2], ""
50
51
  end
51
52
 
52
- it "should return a prerendered response if the url is part of the whitelist" do
53
- request = Rack::MockRequest.env_for "/search/things/123/page", "HTTP_USER_AGENT" => bot
54
- stub_request(:get, @prerender.build_api_url(request)).to_return(:body => "<html></html>")
55
- response = Rack::Prerender.new(@app, whitelist: ['/search', '/help']).call(request)
56
-
57
- assert_equal response[2].body, ["<html></html>"]
58
- end
59
-
60
53
  it "should return a prerendered response if the url is part of the regex specific whitelist" do
61
54
  request = Rack::MockRequest.env_for "/search/things/123/page", "HTTP_USER_AGENT" => bot
62
55
  stub_request(:get, @prerender.build_api_url(request)).to_return(:body => "<html></html>")
@@ -65,13 +58,6 @@ describe Rack::Prerender do
65
58
  assert_equal response[2].body, ["<html></html>"]
66
59
  end
67
60
 
68
- it "should continue to app routes if the url is part of the blacklist" do
69
- request = Rack::MockRequest.env_for "/search/things/123/page", "HTTP_USER_AGENT" => bot
70
- response = Rack::Prerender.new(@app, blacklist: ['/search', '/help']).call(request)
71
-
72
- assert_equal response[2], ""
73
- end
74
-
75
61
  it "should continue to app routes if the url is part of the regex specific blacklist" do
76
62
  request = Rack::MockRequest.env_for "/search/things/123/page", "HTTP_USER_AGENT" => bot
77
63
  response = Rack::Prerender.new(@app, blacklist: ['^/search', '/help']).call(request)
@@ -79,14 +65,6 @@ describe Rack::Prerender do
79
65
  assert_equal response[2], ""
80
66
  end
81
67
 
82
- it "should return a prerendered response if the url is not part of the blacklist" do
83
- request = Rack::MockRequest.env_for "/profile/blah", "HTTP_USER_AGENT" => bot
84
- stub_request(:get, @prerender.build_api_url(request)).to_return(:body => "<html></html>")
85
- response = Rack::Prerender.new(@app, blacklist: ['/search', '/help']).call(request)
86
-
87
- assert_equal response[2].body, ["<html></html>"]
88
- end
89
-
90
68
  it "should return a prerendered response if the url is not part of the regex specific blacklist" do
91
69
  request = Rack::MockRequest.env_for "/profile/search/blah", "HTTP_USER_AGENT" => bot
92
70
  stub_request(:get, @prerender.build_api_url(request)).to_return(:body => "<html></html>")
@@ -95,13 +73,6 @@ describe Rack::Prerender do
95
73
  assert_equal response[2].body, ["<html></html>"]
96
74
  end
97
75
 
98
- it "should continue to app routes if the referer is part of the blacklist" do
99
- request = Rack::MockRequest.env_for "/api/results", "HTTP_USER_AGENT" => bot, "HTTP_REFERER" => '/search'
100
- response = Rack::Prerender.new(@app, blacklist: ['/search', '/help']).call(request)
101
-
102
- assert_equal response[2], ""
103
- end
104
-
105
76
  it "should continue to app routes if the referer is part of the regex specific blacklist" do
106
77
  request = Rack::MockRequest.env_for "/api/results", "HTTP_USER_AGENT" => bot, "HTTP_REFERER" => '/search'
107
78
  response = Rack::Prerender.new(@app, blacklist: ['^/search', '/help']).call(request)
@@ -109,14 +80,6 @@ describe Rack::Prerender do
109
80
  assert_equal response[2], ""
110
81
  end
111
82
 
112
- it "should return a prerendered response if the referer is not part of the blacklist" do
113
- request = Rack::MockRequest.env_for "/api/results", "HTTP_USER_AGENT" => bot, "HTTP_REFERER" => '/search'
114
- stub_request(:get, @prerender.build_api_url(request)).to_return(:body => "<html></html>")
115
- response = Rack::Prerender.new(@app, blacklist: ['/profile', '/help']).call(request)
116
-
117
- assert_equal response[2].body, ["<html></html>"]
118
- end
119
-
120
83
  it "should return a prerendered response if the referer is not part of the regex specific blacklist" do
121
84
  request = Rack::MockRequest.env_for "/api/results", "HTTP_USER_AGENT" => bot, "HTTP_REFERER" => '/profile/search'
122
85
  stub_request(:get, @prerender.build_api_url(request)).to_return(:body => "<html></html>")
@@ -128,6 +91,7 @@ describe Rack::Prerender do
128
91
  describe '#buildApiUrl' do
129
92
  it "should build the correct api url with the default url" do
130
93
  request = Rack::MockRequest.env_for "https://google.com/search?q=javascript"
94
+ ENV['PRERENDER_SERVICE_URL'] = nil
131
95
  assert_equal @prerender.build_api_url(request), 'http://prerender.herokuapp.com/https://google.com/search?q=javascript'
132
96
  end
133
97
 
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: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Hooper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-09 00:00:00.000000000 Z
11
+ date: 2013-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack