class PhantomProxy::ProxyApi
Private Instance Methods
as_image?()
click to toggle source
# File lib/phantom_proxy/proxy/proxy_api.rb, line 47 def as_image? env["HTTP_GET_PAGE_AS_IMAGE"] == "true" || PhantomProxy.always_image? end
canonical_path()
click to toggle source
# File lib/phantom_proxy/proxy/proxy_api.rb, line 59 def canonical_path ["#{protocoll}://#{host}",path].join("/") end
canonical_url()
click to toggle source
# File lib/phantom_proxy/proxy/proxy_api.rb, line 63 def canonical_url [canonical_path, env["params"] ? env["params"].map{|k,v| "#{k}=#{v}"}.join('&') : nil].join("?") end
check_request_security()
click to toggle source
# File lib/phantom_proxy/proxy/proxy_api.rb, line 67 def check_request_security if !hmac_hash || !hmac_time return false end client_time= Time.parse(hmac_time) remote_time= Time.now remote_key = PhantomProxy.hmac_key.update(env['REQUEST_URI']+env['HTTP_HMAC_TIME']).hexdigest if (hmac_hash != remote_key || (remote_time-client_time).abs > 120) # control_panel.add_special_request "@did not pass security check" logger.info "@did not pass security check" return false end return true end
handle_proxy_request()
click to toggle source
# File lib/phantom_proxy/proxy/proxy_api.rb, line 13 def handle_proxy_request return Http.NotAuthorized unless !PhantomProxy.hmac_key || check_request_security phJS = PhantomJS.new PhantomProxy.wait_for(lambda { phJS.getUrl(canonical_url, as_image?, iframes?) }) return image_response(phJS) if as_image? html_response(phJS) end
hmac_hash()
click to toggle source
# File lib/phantom_proxy/proxy/proxy_api.rb, line 84 def hmac_hash env['HTTP_HMAC_KEY'] end
hmac_time()
click to toggle source
# File lib/phantom_proxy/proxy/proxy_api.rb, line 87 def hmac_time env['HTTP_HMAC_TIME'] end
host()
click to toggle source
# File lib/phantom_proxy/proxy/proxy_api.rb, line 31 def host if https? env['SERVER_NAME'] else env['HTTP_HOST'] end end
html_response(phJS)
click to toggle source
# File lib/phantom_proxy/proxy/proxy_api.rb, line 23 def html_response(phJS) [phJS.ready > 0 ? phJS.ready : 404 , {'Content-Type' => 'text/html'}, phJS.dom] end
https?()
click to toggle source
# File lib/phantom_proxy/proxy/proxy_api.rb, line 51 def https? env["SERVER_PORT"] == "443" end
iframes?()
click to toggle source
# File lib/phantom_proxy/proxy/proxy_api.rb, line 43 def iframes? env["HTTP_GET_PAGE_WITH_IFRAMES"] == "true" || PhantomProxy.always_iframe? end
image_response(phJS)
click to toggle source
# File lib/phantom_proxy/proxy/proxy_api.rb, line 27 def image_response(phJS) [200 , {'Content-Type' => 'image/png'}, phJS.image] end
path()
click to toggle source
# File lib/phantom_proxy/proxy/proxy_api.rb, line 39 def path env[nil] ? env[nil][:path] : "" end
protocoll()
click to toggle source
# File lib/phantom_proxy/proxy/proxy_api.rb, line 55 def protocoll https? ? "https" : "http" end