File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -157,7 +157,9 @@ def get_prerendered_page_response(env)
157157 headers [ 'X-Prerender-Token' ] = @options [ :prerender_token ] if @options [ :prerender_token ]
158158 req = Net ::HTTP ::Get . new ( url . request_uri , headers )
159159 req . basic_auth ( ENV [ 'PRERENDER_USERNAME' ] , ENV [ 'PRERENDER_PASSWORD' ] ) if @options [ :basic_auth ]
160- response = Net ::HTTP . start ( url . host , url . port ) { |http | http . request ( req ) }
160+ http = Net ::HTTP . new ( url . host , url . port )
161+ http . use_ssl = true if url . scheme == 'https'
162+ response = http . request ( req )
161163 if response [ 'Content-Encoding' ] == 'gzip'
162164 response . body = ActiveSupport ::Gzip . decompress ( response . body )
163165 response [ 'Content-Length' ] = response . body . length
Original file line number Diff line number Diff line change 7474 end
7575
7676
77+ it "should set use_ssl to true for https prerender_service_url" do
78+ @prerender = Rack ::Prerender . new ( @app , prerender_service_url : 'https://service.prerender.io/' )
79+
80+ request = Rack ::MockRequest . env_for "/search/things/123/page?_escaped_fragment_=" , "HTTP_USER_AGENT" => bot
81+ stub_request ( :get , @prerender . build_api_url ( request ) ) . to_return ( :body => "<html></html>" )
82+ response = @prerender . call ( request )
83+
84+ assert_equal [ "<html></html>" ] , response [ 2 ] . body
85+ end
86+
87+
7788 it "should return a prerendered response if the url is part of the regex specific whitelist" do
7889 request = Rack ::MockRequest . env_for "/search/things/123/page?_escaped_fragment_=" , "HTTP_USER_AGENT" => bot
7990 stub_request ( :get , @prerender . build_api_url ( request ) ) . to_return ( :body => "<html></html>" )
164175 end
165176
166177
178+ it "should build the correct https api url with an initialization variable url" do
179+ @prerender = Rack ::Prerender . new ( @app , prerender_service_url : 'https://prerenderurl.com' )
180+ request = Rack ::MockRequest . env_for "https://google.com/search?q=javascript"
181+ assert_equal 'https://prerenderurl.com/https://google.com/search?q=javascript' , @prerender . build_api_url ( request )
182+ end
183+
184+
167185 # Check CF-Visitor header in order to Work behind CloudFlare with Flexible SSL (https://support.cloudflare.com/hc/en-us/articles/200170536)
168186 it "should build the correct api url for the Cloudflare Flexible SSL support" do
169187 request = Rack ::MockRequest . env_for "http://google.com/search?q=javascript" , { 'CF-VISITOR' => '"scheme":"https"' }
You can’t perform that action at this time.
0 commit comments