proxy-server 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,66 +1,61 @@
1
- PATH
2
- remote: .
3
- specs:
4
- proxy-server (0.0.3)
5
- httpclient
6
- json (>= 1.4.6)
7
- sinatra (>= 1.2.6)
8
- thin
9
-
10
- GEM
11
- remote: http://rubygems.org/
12
- specs:
13
- addressable (2.2.6)
14
- crack (0.3.1)
15
- daemons (1.1.4)
16
- diff-lcs (1.1.3)
17
- eventmachine (1.0.0.beta.4.1-x86-mingw32)
18
- httpclient (2.2.2)
19
- json (1.6.1)
20
- multi_json (1.0.3)
21
- rack (1.3.4)
22
- rack-protection (1.1.4)
23
- rack
24
- rack-test (0.6.1)
25
- rack (>= 1.0)
26
- rake (0.9.2)
27
- rspec (2.7.0)
28
- rspec-core (~> 2.7.0)
29
- rspec-expectations (~> 2.7.0)
30
- rspec-mocks (~> 2.7.0)
31
- rspec-core (2.7.0)
32
- rspec-expectations (2.7.0)
33
- diff-lcs (~> 1.1.2)
34
- rspec-mocks (2.7.0)
35
- simplecov (0.5.4)
36
- multi_json (~> 1.0.3)
37
- simplecov-html (~> 0.5.3)
38
- simplecov-html (0.5.3)
39
- sinatra (1.3.1)
40
- rack (~> 1.3, >= 1.3.4)
41
- rack-protection (~> 1.1, >= 1.1.2)
42
- tilt (~> 1.3, >= 1.3.3)
43
- thin (1.2.11)
44
- daemons (>= 1.0.9)
45
- eventmachine (>= 0.12.6)
46
- rack (>= 1.0.0)
47
- thin (1.2.11-x86-mingw32)
48
- daemons (>= 1.0.9)
49
- eventmachine (>= 0.12.6)
50
- rack (>= 1.0.0)
51
- tilt (1.3.3)
52
- webmock (1.7.6)
53
- addressable (~> 2.2, > 2.2.5)
54
- crack (>= 0.1.7)
55
-
56
- PLATFORMS
57
- ruby
58
- x86-mingw32
59
-
60
- DEPENDENCIES
61
- proxy-server!
62
- rack-test (>= 0.5.7)
63
- rake (>= 0.9.2)
64
- rspec (>= 2.7.0)
65
- simplecov (>= 0.4.2)
66
- webmock
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ proxy-server (0.0.4)
5
+ httpclient
6
+ json (>= 1.4.6)
7
+ sinatra (>= 1.2.6)
8
+ thin
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ addressable (2.2.6)
14
+ crack (0.3.1)
15
+ daemons (1.1.4)
16
+ diff-lcs (1.1.3)
17
+ eventmachine (1.0.0.beta.4.1-x86-mingw32)
18
+ httpclient (2.2.3)
19
+ json (1.6.1)
20
+ multi_json (1.0.3)
21
+ rack (1.3.5)
22
+ rack-protection (1.1.4)
23
+ rack
24
+ rack-test (0.6.1)
25
+ rack (>= 1.0)
26
+ rake (0.9.2.2)
27
+ rspec (2.7.0)
28
+ rspec-core (~> 2.7.0)
29
+ rspec-expectations (~> 2.7.0)
30
+ rspec-mocks (~> 2.7.0)
31
+ rspec-core (2.7.1)
32
+ rspec-expectations (2.7.0)
33
+ diff-lcs (~> 1.1.2)
34
+ rspec-mocks (2.7.0)
35
+ simplecov (0.5.4)
36
+ multi_json (~> 1.0.3)
37
+ simplecov-html (~> 0.5.3)
38
+ simplecov-html (0.5.3)
39
+ sinatra (1.3.1)
40
+ rack (~> 1.3, >= 1.3.4)
41
+ rack-protection (~> 1.1, >= 1.1.2)
42
+ tilt (~> 1.3, >= 1.3.3)
43
+ thin (1.3.1)
44
+ daemons (>= 1.0.9)
45
+ eventmachine (>= 0.12.6)
46
+ rack (>= 1.0.0)
47
+ tilt (1.3.3)
48
+ webmock (1.7.6)
49
+ addressable (~> 2.2, > 2.2.5)
50
+ crack (>= 0.1.7)
51
+
52
+ PLATFORMS
53
+ x86-mingw32
54
+
55
+ DEPENDENCIES
56
+ proxy-server!
57
+ rack-test (>= 0.5.7)
58
+ rake (>= 0.9.2)
59
+ rspec (>= 2.7.0)
60
+ simplecov (>= 0.4.2)
61
+ webmock
@@ -1,8 +1,9 @@
1
- require 'rack'
2
1
  require 'httpclient'
2
+ require "thin"
3
+ require "rack/content_length"
4
+ require "rack/chunked"
3
5
 
4
6
  class ProxyServer
5
-
6
7
  attr_reader :upstream_proxy, :port
7
8
  attr_reader :requests, :track_requests, :substitute_requests
8
9
 
@@ -25,7 +26,11 @@ class ProxyServer
25
26
 
26
27
  def run
27
28
  @proxy_thread = Thread.new do
28
- Rack::Handler::WEBrick.run self, :Port => self.port, :AccessLog => []
29
+ server = ::Thin::Server.new('0.0.0.0',
30
+ self.port,
31
+ self)
32
+
33
+ server.start
29
34
  end
30
35
  end
31
36
 
@@ -45,25 +50,27 @@ class ProxyServer
45
50
  response = get_substitution(env)
46
51
  return response unless response.nil?
47
52
 
53
+
48
54
  method = env['REQUEST_METHOD']
49
- uri = "http://#{env['HTTP_HOST']}#{env['PATH_INFO']}"
50
- params = get_params(env['QUERY_STRING'])
55
+ uri = get_url(env)
51
56
  body = get_request_body(env)
52
57
  headers = get_request_headers(env)
53
- #
54
- #p "YES" if uri.include? 'unicast.com'
55
- #p uri if uri.include? 'unicast.com'
56
- #[ 200, {}, ['']] if uri.include? 'unicast.com'
57
58
 
58
- response = @client.request(method, uri, params, body, headers)
59
+ query_string_match = uri.match(/\?(.*)$/)
60
+ query_string = query_string_match ? query_string_match[1] : ""
61
+ params = get_params(query_string)
59
62
 
63
+ response = @client.request(method, uri, params, body, headers)
60
64
  [ response.status, response.headers, [response.body] ]
61
65
  end
62
66
 
67
+ def get_url(env)
68
+ env['REQUEST_URI'] || "http://#{env['SERVER_NAME']}#{env['PATH_INFO']}#{env['QUERY_STRING'].length > 0 ? '?'+env['QUERY_STRING'] : ''}"
69
+ end
70
+
63
71
  def get_substitution(env)
64
- uri = env['REQUEST_URI'] || "http://#{env['SERVER_NAME']}#{env['PATH_INFO']}#{env['QUERY_STRING'] ? '?'+env['QUERY_STRING'] : ''}"
65
72
  @substitute_requests.each do |pattern, options|
66
- if Regexp.new(pattern) =~ uri
73
+ if Regexp.new(pattern) =~ get_url(env)
67
74
  return get_substituted_response(options)
68
75
  end
69
76
  end
@@ -94,8 +101,7 @@ class ProxyServer
94
101
  end
95
102
 
96
103
  def log_request(env)
97
-
98
- url = env['REQUEST_URI'] || "http://#{env['SERVER_NAME']}#{env['PATH_INFO']}#{env['QUERY_STRING'].length>0 ? '?'+env['QUERY_STRING'] : ''}"
104
+ url = get_url(env)
99
105
  @track_requests.each do |pattern|
100
106
  @requests << url if Regexp.new(pattern) =~ url
101
107
  end
@@ -113,5 +119,4 @@ class ProxyServer
113
119
  env.each {|k,v| if k =~ /HTTP_(\w+)/ then headers[$1] = v end }
114
120
  headers
115
121
  end
116
- end
117
-
122
+ end
data/proxy-server.gemspec CHANGED
@@ -2,7 +2,7 @@ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'proxy-server'
5
- s.version = '0.0.3'
5
+ s.version = '0.0.4'
6
6
  s.authors = ["Derek Ekins"]
7
7
  s.description = 'Proxy server'
8
8
  s.summary = "proxy-server-#{s.version}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxy-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-11-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &11366952 !ruby/object:Gem::Requirement
16
+ requirement: &9865548 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.4.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *11366952
24
+ version_requirements: *9865548
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sinatra
27
- requirement: &11366664 !ruby/object:Gem::Requirement
27
+ requirement: &9865260 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.2.6
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *11366664
35
+ version_requirements: *9865260
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: httpclient
38
- requirement: &11366436 !ruby/object:Gem::Requirement
38
+ requirement: &9865032 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *11366436
46
+ version_requirements: *9865032
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: thin
49
- requirement: &11366160 !ruby/object:Gem::Requirement
49
+ requirement: &9864756 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *11366160
57
+ version_requirements: *9864756
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &11365860 !ruby/object:Gem::Requirement
60
+ requirement: &9864456 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.9.2
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *11365860
68
+ version_requirements: *9864456
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &11365560 !ruby/object:Gem::Requirement
71
+ requirement: &9864156 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 2.7.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *11365560
79
+ version_requirements: *9864156
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: simplecov
82
- requirement: &11365284 !ruby/object:Gem::Requirement
82
+ requirement: &9863880 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 0.4.2
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *11365284
90
+ version_requirements: *9863880
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: webmock
93
- requirement: &11365056 !ruby/object:Gem::Requirement
93
+ requirement: &9863652 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *11365056
101
+ version_requirements: *9863652
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rack-test
104
- requirement: &11364732 !ruby/object:Gem::Requirement
104
+ requirement: &9863328 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: 0.5.7
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *11364732
112
+ version_requirements: *9863328
113
113
  description: Proxy server
114
114
  email: derek@spathi.com
115
115
  executables: []
@@ -142,22 +142,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
142
  - - ! '>='
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
- segments:
146
- - 0
147
- hash: -732842897
148
145
  required_rubygems_version: !ruby/object:Gem::Requirement
149
146
  none: false
150
147
  requirements:
151
148
  - - ! '>='
152
149
  - !ruby/object:Gem::Version
153
150
  version: '0'
154
- segments:
155
- - 0
156
- hash: -732842897
157
151
  requirements: []
158
152
  rubyforge_project:
159
153
  rubygems_version: 1.8.11
160
154
  signing_key:
161
155
  specification_version: 3
162
- summary: proxy-server-0.0.3
156
+ summary: proxy-server-0.0.4
163
157
  test_files: []