phantom_proxy 1.2.10 → 1.2.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  require 'net/http'
2
2
  require 'hmac-md5'
3
+ require 'base64'
3
4
 
4
5
  module PhantomJSProxy
5
6
  class PhantomJSServer
@@ -25,17 +26,20 @@ module PhantomJSProxy
25
26
 
26
27
  def check_for_route(url)
27
28
  if /\.js/i.match(url) and !/\.jsp/i.match(url)
28
- return 'text/html';
29
+ return 'text/html'
29
30
  end
30
31
  if /\.css/i.match(url)
31
32
  return 'text/css'
32
33
  end
33
34
  if /\.png/i.match(url) or /\.jpg/i.match(url) or /\.jpeg/i.match(url) or /\.gif/i.match(url)
34
- return 'image/*';
35
+ return 'image/*'
35
36
  end
36
37
  if /phantom_proxy_control_panel/.match(url)
37
38
  return 'control_panel'
38
39
  end
40
+ if /phantomProxy\.get/.match(url)
41
+ return "base64"
42
+ end
39
43
  "none"
40
44
  end
41
45
 
@@ -73,7 +77,41 @@ module PhantomJSProxy
73
77
  end
74
78
  return true
75
79
  end
76
-
80
+
81
+ def getOptions(env)
82
+ if defined? env['HTTP_GET_PAGE_AS_IMAGE']
83
+ picture = env['HTTP_GET_PAGE_AS_IMAGE']
84
+ else
85
+ picture = true
86
+ end
87
+
88
+ if defined? env['HTTP_GET_PAGE_WITH_IFRAMES']
89
+ loadFrames = env['HTTP_GET_PAGE_WITH_IFRAMES']
90
+ else
91
+ loadFrames = false
92
+ end
93
+
94
+ return picture,loadFrames
95
+ end
96
+
97
+ def prepareUrl(env, params, req, https_request, type)
98
+ if type == "none"
99
+ url = env['REQUEST_URI'];
100
+ if https_request
101
+ url['http'] = 'https'
102
+ url[':443'] = ''
103
+ end
104
+
105
+ if params.length > 0
106
+ url += '?'+params;
107
+ end
108
+ return url
109
+ end
110
+ url = Base64.decode64(req.params["address"])
111
+ env['rack.errors'].write("After Base64 decoding: "+url)
112
+ return url
113
+ end
114
+
77
115
  def call(env)
78
116
  control_panel.add_request
79
117
 
@@ -103,7 +141,7 @@ module PhantomJSProxy
103
141
  type = check_for_route(env['REQUEST_URI'])
104
142
  if type == "control_panel"
105
143
  return control_panel.show()
106
- elsif type != "none"
144
+ elsif type != "none" and type != "base64"
107
145
  control_panel.add_special_request "@forward_requests"
108
146
  return route(env, type)
109
147
  else
@@ -112,27 +150,9 @@ module PhantomJSProxy
112
150
 
113
151
  env['rack.errors'].write("Extract the uri\n")
114
152
 
115
- if defined? env['HTTP_GET_PAGE_AS_IMAGE']
116
- picture = env['HTTP_GET_PAGE_AS_IMAGE']
117
- else
118
- picture = true
119
- end
120
-
121
- if defined? env['HTTP_GET_PAGE_WITH_IFRAMES']
122
- loadFrames = env['HTTP_GET_PAGE_WITH_IFRAMES']
123
- else
124
- loadFrames = false
125
- end
126
-
127
- url = env['REQUEST_URI'];
128
- if https_request
129
- url['http'] = 'https'
130
- url[':443'] = ''
131
- end
153
+ picture,loadFrames = getOptions(env)
132
154
 
133
- if params.length > 0
134
- url += '?'+params;
135
- end
155
+ url = prepareUrl(env, params, req, https_request, type)
136
156
 
137
157
  phJS.getUrl(url, picture, loadFrames)
138
158
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phantom_proxy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 10
10
- version: 1.2.10
9
+ - 11
10
+ version: 1.2.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel Sudmann
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-10-22 00:00:00 +02:00
18
+ date: 2013-04-23 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency