prerender_rails 1.0.1 → 1.0.3

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
  SHA1:
3
- metadata.gz: 5e0a30152ab67e4ed90d572fa4fea5d5b7668b69
4
- data.tar.gz: 3061266e1581da3da55955244cd95c263c607c88
3
+ metadata.gz: 61a58c5f4239f335d7a4a22784a175e36be07306
4
+ data.tar.gz: d5537ee321c8f97586f4434be35299b2673993fb
5
5
  SHA512:
6
- metadata.gz: c01de33e47e9d0ef09391868bdfbbef22070f862c3ea6acf9a858808b3c6ebc2f401c9604c06f9c8f662922b63d7aacb1df495773120f49382036c7fafb9ae83
7
- data.tar.gz: 7c5a1b22a80375cd5a9778e0196e45f58a5d9a70ba37a03143fdd81afff0c2749e0c8dacb59a00903ba6419303b966cfc85e005e89000c7b51316bba5151197b
6
+ metadata.gz: e6bccf3db6f4fe476a70852c1deadec8de6ab835f157b3527bf57797c6538063680da1b9fa8f0d1d67de568c916046adcdfafd1e9b2b6769c5ec0754a7e76cca
7
+ data.tar.gz: 7656f38253b8253e55df48a70f4e161ef40f5380acf29ec0357f9739606cd88e6aa9f92640e9e67411c587d51cf2d40113867424aaeab9dbed4b910419b97a22
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- Prerender Rails [![Build Status](https://travis-ci.org/prerender/prerender_rails.png)](https://travis-ci.org/prerender/prerender_rails) [![Gem Version](https://badge.fury.io/rb/prerender_rails.png)](http://badge.fury.io/rb/prerender_rails)
2
- ===========================
1
+ Prerender Rails [![Stories in Ready](https://badge.waffle.io/prerender/prerender_rails.png?label=ready&title=Ready)](https://waffle.io/prerender/prerender_rails) [![Build Status](https://travis-ci.org/prerender/prerender_rails.png)](https://travis-ci.org/prerender/prerender_rails) [![Gem Version](https://badge.fury.io/rb/prerender_rails.png)](http://badge.fury.io/rb/prerender_rails)
2
+ ===========================
3
3
 
4
4
  Google, Facebook, Twitter, Yahoo, and Bing are constantly trying to view your website... but they don't execute javascript. That's why we built Prerender. Prerender is perfect for AngularJS SEO, BackboneJS SEO, EmberJS SEO, and any other javascript framework.
5
5
 
@@ -104,6 +104,13 @@ config.middleware.use Rack::Prerender,
104
104
  end)
105
105
  ```
106
106
 
107
+ ### protocol
108
+
109
+ Option to hard-set the protocol for Prerender accessing your site instead of the middleware figuring out the protocol based on the request.
110
+ ```ruby
111
+ config.middleware.use Rack::Prerender, protocol: 'https'
112
+ ```
113
+
107
114
  ## Caching
108
115
 
109
116
  This rails middleware is ready to be used with [redis](http://redis.io/) or [memcached](http://memcached.org/) to return prerendered pages in milliseconds.
@@ -164,4 +171,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
164
171
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
165
172
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
166
173
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
167
- THE SOFTWARE.
174
+ THE SOFTWARE.
@@ -19,7 +19,8 @@ module Rack
19
19
  'bufferbot',
20
20
  'quora link preview',
21
21
  'showyoubot',
22
- 'outbrain'
22
+ 'outbrain',
23
+ 'pinterest'
23
24
  ]
24
25
 
25
26
  @extensions_to_ignore = [
@@ -90,12 +91,13 @@ module Rack
90
91
  end
91
92
  end
92
93
 
93
- @app.call(env)
94
+ @app.call(env)
94
95
  end
95
96
 
96
97
 
97
98
  def should_show_prerendered_page(env)
98
99
  user_agent = env['HTTP_USER_AGENT']
100
+ buffer_agent = env['X-BUFFERBOT']
99
101
  is_requesting_prerendered_page = false
100
102
 
101
103
  return false if !user_agent
@@ -108,6 +110,9 @@ module Rack
108
110
  #if it is a bot...show prerendered page
109
111
  is_requesting_prerendered_page = true if @crawler_user_agents.any? { |crawler_user_agent| user_agent.downcase.include?(crawler_user_agent.downcase) }
110
112
 
113
+ #if it is BufferBot...show prerendered page
114
+ is_requesting_prerendered_page = true if buffer_agent
115
+
111
116
  #if it is a bot and is requesting a resource...dont prerender
112
117
  return false if @extensions_to_ignore.any? { |extension| request.path.include? extension }
113
118
 
@@ -126,7 +131,7 @@ module Rack
126
131
  blacklistedUrl || blacklistedReferer
127
132
  }
128
133
  return false
129
- end
134
+ end
130
135
 
131
136
  return is_requesting_prerendered_page
132
137
  end
@@ -164,8 +169,13 @@ module Rack
164
169
  end
165
170
 
166
171
  if env["X-FORWARDED-PROTO"]
167
- new_env["HTTPS"] = true and new_env["rack.url_scheme"] = "https" and new_env["SERVER_PORT"] = 443 if env["X-FORWARDED-PROTO"] == "https"
168
- new_env["HTTPS"] = false and new_env["rack.url_scheme"] = "http" and new_env["SERVER_PORT"] = 80 if env["X-FORWARDED-PROTO"] == "http"
172
+ new_env["HTTPS"] = true and new_env["rack.url_scheme"] = "https" and new_env["SERVER_PORT"] = 443 if env["X-FORWARDED-PROTO"].split(',')[0] == "https"
173
+ new_env["HTTPS"] = false and new_env["rack.url_scheme"] = "http" and new_env["SERVER_PORT"] = 80 if env["X-FORWARDED-PROTO"].split(',')[0] == "http"
174
+ end
175
+
176
+ if @options[:protocol]
177
+ new_env["HTTPS"] = true and new_env["rack.url_scheme"] = "https" and new_env["SERVER_PORT"] = 443 if @options[:protocol] == "https"
178
+ new_env["HTTPS"] = false and new_env["rack.url_scheme"] = "http" and new_env["SERVER_PORT"] = 80 if @options[:protocol] == "http"
169
179
  end
170
180
 
171
181
  url = Rack::Request.new(new_env).url
@@ -193,7 +203,7 @@ module Rack
193
203
  return nil unless @options[:before_render]
194
204
 
195
205
  cached_render = @options[:before_render].call(env)
196
-
206
+
197
207
  if cached_render && cached_render.is_a?(String)
198
208
  Rack::Response.new(cached_render, 200, [])
199
209
  elsif cached_render && cached_render.is_a?(Rack::Response)
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "prerender_rails"
5
- spec.version = "1.0.1"
5
+ spec.version = "1.0.3"
6
6
  spec.authors = ["Todd Hooper"]
7
7
  spec.email = ["todd@prerender.io"]
8
8
  spec.description = %q{Rails middleware to prerender your javascript heavy pages on the fly by a phantomjs service}
@@ -1,5 +1,5 @@
1
1
  require_relative '../test_helper'
2
-
2
+
3
3
  describe Rack::Prerender do
4
4
 
5
5
  bot = 'Baiduspider+(+http://www.baidu.com/search/spider.htm)'
@@ -134,7 +134,7 @@ describe Rack::Prerender do
134
134
  assert_equal( { 'test' => 'test2Header', "Content-Length"=>"20"}, response[2].headers )
135
135
  end
136
136
 
137
-
137
+
138
138
  describe '#buildApiUrl' do
139
139
  it "should build the correct api url with the default url" do
140
140
  request = Rack::MockRequest.env_for "https://google.com/search?q=javascript"
@@ -167,11 +167,26 @@ describe Rack::Prerender do
167
167
 
168
168
 
169
169
  # Check X-Forwarded-Proto because Heroku SSL Support terminates at the load balancer
170
- it "should build the correct api url for the Heroku SSL Addon support" do
170
+ it "should build the correct api url for the Heroku SSL Addon support with single value" do
171
171
  request = Rack::MockRequest.env_for "http://google.com/search?q=javascript", { 'X-FORWARDED-PROTO' => 'https'}
172
172
  ENV['PRERENDER_SERVICE_URL'] = nil
173
173
  assert_equal 'http://service.prerender.io/https://google.com/search?q=javascript', @prerender.build_api_url(request)
174
174
  end
175
+
176
+
177
+ # Check X-Forwarded-Proto because Heroku SSL Support terminates at the load balancer
178
+ it "should build the correct api url for the Heroku SSL Addon support with double value" do
179
+ request = Rack::MockRequest.env_for "http://google.com/search?q=javascript", { 'X-FORWARDED-PROTO' => 'https,http'}
180
+ ENV['PRERENDER_SERVICE_URL'] = nil
181
+ assert_equal 'http://service.prerender.io/https://google.com/search?q=javascript', @prerender.build_api_url(request)
182
+ end
183
+
184
+ it "should build the correct api url for the protocol option" do
185
+ @prerender = Rack::Prerender.new(@app, protocol: 'https')
186
+ request = Rack::MockRequest.env_for "http://google.com/search?q=javascript"
187
+ ENV['PRERENDER_SERVICE_URL'] = nil
188
+ assert_equal 'http://service.prerender.io/https://google.com/search?q=javascript', @prerender.build_api_url(request)
189
+ end
175
190
  end
176
191
 
177
192
  end
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: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Hooper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-09 00:00:00.000000000 Z
11
+ date: 2014-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack