em-proxy 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 05d04c15535a7a3dc1b1d6dbe900465dd2a61a30
4
+ data.tar.gz: 2f14121398f689020237bdea0bf45b1e0141fdee
5
+ SHA512:
6
+ metadata.gz: f40bf0a4ddd86497cd79d405ec8bf8341f428c30b6821ee3a3832f0469bb888cfc8bc942c2f7a9e744e22985d9f86cd1452a510195e37231d56babda3e89e0d4
7
+ data.tar.gz: ed2afacaaa70fb79d607989b321d05553e5ba10f7982418d0344d17af5a1468c32c650175907c1bfacb8419c0079daeecc8897903ff78debe8cd683529a71d4f
@@ -1,5 +1,4 @@
1
+ sudo: false
2
+ language: ruby
1
3
  rvm:
2
- - 1.8.7
3
- - 1.9.2
4
- - 1.9.3
5
-
4
+ - 2.3.0
@@ -1,34 +1,41 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- em-proxy (0.1.7)
4
+ em-proxy (0.1.8)
5
5
  eventmachine
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- addressable (2.2.6)
11
- ansi (1.4.0)
12
- diff-lcs (1.1.3)
13
- em-http-request (1.0.0)
14
- addressable (>= 2.2.3)
15
- em-socksify
16
- eventmachine (>= 1.0.0.beta.3)
17
- http_parser.rb (>= 0.5.2)
18
- em-socksify (0.1.0)
19
- eventmachine
20
- eventmachine (1.0.0)
21
- http_parser.rb (0.5.3)
22
- posix-spawn (0.3.6)
23
- rake (0.9.2.2)
24
- rspec (2.7.0)
25
- rspec-core (~> 2.7.0)
26
- rspec-expectations (~> 2.7.0)
27
- rspec-mocks (~> 2.7.0)
28
- rspec-core (2.7.1)
29
- rspec-expectations (2.7.0)
30
- diff-lcs (~> 1.1.2)
31
- rspec-mocks (2.7.0)
10
+ addressable (2.4.0)
11
+ ansi (1.5.0)
12
+ cookiejar (0.3.3)
13
+ diff-lcs (1.2.5)
14
+ em-http-request (1.1.4)
15
+ addressable (>= 2.3.4)
16
+ cookiejar (!= 0.3.1)
17
+ em-socksify (>= 0.3)
18
+ eventmachine (>= 1.0.3)
19
+ http_parser.rb (>= 0.6.0)
20
+ em-socksify (0.3.1)
21
+ eventmachine (>= 1.0.0.beta.4)
22
+ eventmachine (1.2.0.1)
23
+ http_parser.rb (0.6.0)
24
+ posix-spawn (0.3.11)
25
+ rake (11.2.2)
26
+ rspec (3.4.0)
27
+ rspec-core (~> 3.4.0)
28
+ rspec-expectations (~> 3.4.0)
29
+ rspec-mocks (~> 3.4.0)
30
+ rspec-core (3.4.4)
31
+ rspec-support (~> 3.4.0)
32
+ rspec-expectations (3.4.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.4.0)
35
+ rspec-mocks (3.4.1)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.4.0)
38
+ rspec-support (3.4.1)
32
39
 
33
40
  PLATFORMS
34
41
  ruby
@@ -40,3 +47,6 @@ DEPENDENCIES
40
47
  posix-spawn
41
48
  rake
42
49
  rspec
50
+
51
+ BUNDLED WITH
52
+ 1.12.5
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2009 Ilya Grigorik
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "em-proxy"
6
- s.version = "0.1.8"
6
+ s.version = "0.1.9"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Ilya Grigorik"]
9
9
  s.email = ["ilya@igvita.com"]
@@ -55,6 +55,7 @@ module BalancingProxy
55
55
  @strategy = strategy.to_sym
56
56
  case @strategy
57
57
  when :balanced
58
+ pp [list, list.sort_by { |b| b.load }.first]
58
59
  backend = list.sort_by { |b| b.load }.first
59
60
  when :roundrobin
60
61
  @pool = list.clone if @pool.nil? || @pool.empty?
@@ -12,6 +12,8 @@ puts "listening on #{host}:#{port}..."
12
12
 
13
13
  Proxy.start(:host => host, :port => port) do |conn|
14
14
 
15
+ @buffer = ''
16
+
15
17
  @p = Http::Parser.new
16
18
  @p.on_headers_complete = proc do |h|
17
19
  session = UUID.generate
@@ -19,19 +21,23 @@ Proxy.start(:host => host, :port => port) do |conn|
19
21
 
20
22
  host, port = h['Host'].split(':')
21
23
  conn.server session, :host => host, :port => (port || 80) #, :bind_host => conn.sock[0] - # for bind ip
22
-
23
- conn.relay_to_servers @buffer
24
24
 
25
- @buffer.clear
25
+ conn.relay_to_servers @buffer
26
+ @buffer = nil
26
27
  end
27
28
 
28
- @buffer = ''
29
-
30
29
  conn.on_connect do |data,b|
31
30
  puts [:on_connect, data, b].inspect
32
31
  end
33
32
 
34
33
  conn.on_data do |data|
34
+ if @buffer
35
+ @buffer << data
36
+
37
+ nil
38
+ else
39
+ @
40
+
35
41
  @buffer << data
36
42
  @p << data
37
43
 
@@ -27,8 +27,8 @@ module EventMachine
27
27
 
28
28
  # Notify upstream plexer that the backend server is done
29
29
  # processing the request
30
- def unbind
31
- debug [@name, :unbind]
30
+ def unbind(reason = nil)
31
+ debug [@name, :unbind, reason]
32
32
  @plexer.unbind_backend(@name)
33
33
  end
34
34
 
@@ -12,9 +12,17 @@ module EventMachine
12
12
  ##### EventMachine
13
13
  def initialize(options)
14
14
  @debug = options[:debug] || false
15
+ @tls_key = options[:tls_key] || false
16
+ @tls_cert = options[:tls_cert] || false
15
17
  @servers = {}
16
18
  end
17
19
 
20
+ def post_init
21
+ if @tls_key and @tls_cert
22
+ start_tls :private_key_file => @tls_key, :cert_chain_file => @tls_cert, :verify_peer => false
23
+ end
24
+ end
25
+
18
26
  def receive_data(data)
19
27
  debug [:connection, data]
20
28
  processed = @on_data.call(data) if @on_data
@@ -97,12 +105,12 @@ module EventMachine
97
105
  @on_connect.call(name) if @on_connect
98
106
  end
99
107
 
100
- def unbind
101
- debug [:unbind, :connection]
108
+ def unbind(reason = nil)
109
+ debug [:unbind, :connection, reason]
102
110
 
103
111
  # terminate any unfinished connections
104
112
  @servers.values.compact.each do |s|
105
- s.close_connection
113
+ s.close_connection_after_writing
106
114
  end
107
115
  end
108
116
 
@@ -85,8 +85,8 @@ describe BalancingProxy do
85
85
  class BalancingProxy::Backend
86
86
  def self.list
87
87
  @list ||= [
88
- {:url => "http://127.0.0.3:3000", :load => 2},
89
- {:url => "http://127.0.0.2:3000", :load => 1},
88
+ {:url => "http://127.0.0.3:3000", :load => 4},
89
+ {:url => "http://127.0.0.2:3000", :load => 2},
90
90
  {:url => "http://127.0.0.1:3000", :load => 0}
91
91
  ].map { |backend| new backend }
92
92
  end
@@ -94,8 +94,8 @@ describe BalancingProxy do
94
94
 
95
95
  BalancingProxy::Backend.select.host.should == '127.0.0.1'
96
96
  BalancingProxy::Backend.select.host.should == '127.0.0.1'
97
- BalancingProxy::Backend.select.host.should == '127.0.0.2'
98
- BalancingProxy::Backend.select.host.should == '127.0.0.3'
97
+ BalancingProxy::Backend.select.host.should_not == '127.0.0.3'
98
+ BalancingProxy::Backend.select.host.should_not == '127.0.0.3'
99
99
  end
100
100
 
101
101
  end
@@ -62,24 +62,24 @@ describe Proxy do
62
62
  end
63
63
  end
64
64
 
65
- it "should duplex TCP traffic to two backends google & yahoo" do
65
+ it "should duplex TCP traffic to two backends" do
66
66
  EM.run do
67
67
  EventMachine.add_timer(0.1) do
68
68
  EventMachine::HttpRequest.new('http://127.0.0.1:8080/test').get({:timeout => 1})
69
69
  end
70
70
 
71
71
  Proxy.start(:host => "0.0.0.0", :port => 8080) do |conn|
72
- conn.server :goog, :host => "google.com", :port => 80
73
- conn.server :yhoo, :host => "yahoo.com", :port => 80
72
+ conn.server :goog1, :host => "google.com", :port => 80
73
+ conn.server :goog2, :host => "google.com", :port => 80
74
74
  conn.on_data { |data| data }
75
75
 
76
76
  seen = []
77
77
  conn.on_response do |backend, resp|
78
78
  case backend
79
- when :goog then
79
+ when :goog1 then
80
80
  resp.should =~ /404/
81
81
  seen.push backend
82
- when :yhoo
82
+ when :goog2
83
83
  resp.should =~ /404/
84
84
  seen.push backend
85
85
  end
@@ -112,7 +112,7 @@ describe Proxy do
112
112
  conn.server :goog, :host => "google.com", :port => 80
113
113
  conn.on_data { |data| data }
114
114
  conn.on_response do |backend, data|
115
- data.gsub(/^HTTP\/1.1 200/, 'HTTP/1.1 404')
115
+ data.gsub(/^HTTP\/1.1 301/, 'HTTP/1.1 404')
116
116
  end
117
117
  end
118
118
  end
metadata CHANGED
@@ -1,110 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
5
- prerelease:
4
+ version: 0.1.9
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ilya Grigorik
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-13 00:00:00.000000000 Z
11
+ date: 2016-07-11 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: eventmachine
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: em-http-request
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: ansi
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rake
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: posix-spawn
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - ">="
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - ">="
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  description: EventMachine Proxy DSL
@@ -115,12 +102,13 @@ executables:
115
102
  extensions: []
116
103
  extra_rdoc_files: []
117
104
  files:
118
- - .gitignore
119
- - .rspec
120
- - .travis.yml
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
121
108
  - CHANGELOG.md
122
109
  - Gemfile
123
110
  - Gemfile.lock
111
+ - LICENSE
124
112
  - README.md
125
113
  - Rakefile
126
114
  - bin/em-proxy
@@ -149,27 +137,26 @@ files:
149
137
  - spec/support/echo_server.rb
150
138
  homepage: http://github.com/igrigorik/em-proxy
151
139
  licenses: []
140
+ metadata: {}
152
141
  post_install_message:
153
142
  rdoc_options: []
154
143
  require_paths:
155
144
  - lib
156
145
  required_ruby_version: !ruby/object:Gem::Requirement
157
- none: false
158
146
  requirements:
159
- - - ! '>='
147
+ - - ">="
160
148
  - !ruby/object:Gem::Version
161
149
  version: '0'
162
150
  required_rubygems_version: !ruby/object:Gem::Requirement
163
- none: false
164
151
  requirements:
165
- - - ! '>='
152
+ - - ">="
166
153
  - !ruby/object:Gem::Version
167
154
  version: '0'
168
155
  requirements: []
169
156
  rubyforge_project: em-proxy
170
- rubygems_version: 1.8.24
157
+ rubygems_version: 2.5.1
171
158
  signing_key:
172
- specification_version: 3
159
+ specification_version: 4
173
160
  summary: EventMachine Proxy DSL
174
161
  test_files:
175
162
  - spec/balancing_spec.rb