em-proxy 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -1 +1,3 @@
1
1
  .bundle
2
+ pkg
3
+
data/.rspec CHANGED
@@ -0,0 +1,2 @@
1
+ --format=documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+
@@ -0,0 +1,59 @@
1
+ 0.1.8 (December 12, 2012)
2
+ --------------------
3
+
4
+ * [#28](https://github.com/igrigorik/em-proxy/pull/28) - Fix: bin script - close connections only on relay response - [@bo-chen](https://github.com/bo-chen).
5
+ * [#31](https://github.com/igrigorik/em-proxy/pull/31) - Added support for proxying to a unix domain socket - [@dblock](https://github.com/dblock).
6
+ * [#34](https://github.com/igrigorik/em-proxy/pull/34) - Fix: duplex TCP traffic to two backends spec race condition - [@dblock](https://github.com/dblock).
7
+
8
+ 0.1.7 (October 13, 2012)
9
+ ------------------------
10
+
11
+ * Allow force-close on upstream connections - [@igrigoric](https://github.com/igrigorik).
12
+ * [#25](https://github.com/igrigorik/em-proxy/pull/25): Added `bind` support - [@kostya](https://github.com/kostya).
13
+ * [#27](https://github.com/igrigorik/em-proxy/pull/27): Alias `sock` for `get_sockname` - [@kostya](https://github.com/kostya).
14
+
15
+ 0.1.6 (December 27, 2011)
16
+ -------------------------
17
+
18
+ * Added HTTP proxy example - [@igrigoric](https://github.com/igrigorik).
19
+ * [#11](https://github.com/igrigorik/em-proxy/issues/11) - Fix: closing the client connection immediately after servers connection are closed - [@igrigoric](https://github.com/igrigorik).
20
+ * [#13](https://github.com/igrigorik/em-proxy/pull/13): Removed duplicate `unbind_backend` - [@outself](https://github.com/outself).
21
+ * [#20](https://github.com/igrigorik/em-proxy/issues/20): Fix: don't buffer data in back-end - [@igrigoric](https://github.com/igrigorik).
22
+
23
+ 0.1.5 (January 16, 2011)
24
+ ------------------------
25
+
26
+ * Added `em-proxy` bin script for easy proxy debugging & relay use cases - [@igrigoric](https://github.com/igrigorik).
27
+ * Replaced Jeweler with Bundler - [@igrigoric](https://github.com/igrigorik).
28
+ * Added example of a simple load-balancing proxy - [@karmi](https://github.com/karmi).
29
+
30
+ 0.1.4 (October 3, 2010)
31
+ -----------------------
32
+
33
+ * Fix: use `instance_eval` to allow unbind - [@igrigoric](https://github.com/igrigorik).
34
+
35
+ 0.1.3 (May 29, 2010)
36
+ --------------------
37
+
38
+ * Fix: `on_connect` should fire after connection is established to each backend - [@igrigoric](https://github.com/igrigorik).
39
+ * Fix: `get_peername` can return nil - [@mdkent](https://github.com/mdkent).
40
+
41
+ 0.1.2 (March 26, 2010)
42
+ ----------------------
43
+
44
+ * Fix: wait until finishing writing on the frontend - [@eudoxa](https://github.com/eudoxa).
45
+ * Removed `:done` callback in `on_finish` - [@igrigoric](https://github.com/igrigorik).
46
+ * Ruby 1.9 compatibility - [@dsander](https://github.com/dsander).
47
+ * Use EM's `proxy_incomming_to` to do low-level data relaying - [@dsander](https://github.com/dsander).
48
+ * Use `Proc#call` instead of `Object#instance_exec` - [@dsander](https://github.com/dsander).
49
+ * Added `on_connect` callback, peer helper method - [@dsander](https://github.com/dsander).
50
+ * Added schema-free mysql example - [@igrigoric](https://github.com/igrigorik).
51
+ * Added support for async processing within the `on_data` callback - [@igrigoric](https://github.com/igrigorik).
52
+
53
+ 0.1.1 (October 25, 2009)
54
+ ------------------------
55
+
56
+ * Initial public release - [@igrigoric](https://github.com/igrigorik).
57
+ * Simple port forwarder - [@igrigoric](https://github.com/igrigorik).
58
+ * Duplex, interceptor, smtp whitelist, beanstalkd interceptor, smtp spam filter and selective forward examples - [@igrigoric](https://github.com/igrigorik).
59
+ * Control debug output - [@imbriaco](https://github.com/imbriaco).
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- em-proxy (0.1.6)
4
+ em-proxy (0.1.7)
5
5
  eventmachine
6
6
 
7
7
  GEM
@@ -17,8 +17,9 @@ GEM
17
17
  http_parser.rb (>= 0.5.2)
18
18
  em-socksify (0.1.0)
19
19
  eventmachine
20
- eventmachine (1.0.0.beta.4)
20
+ eventmachine (1.0.0)
21
21
  http_parser.rb (0.5.3)
22
+ posix-spawn (0.3.6)
22
23
  rake (0.9.2.2)
23
24
  rspec (2.7.0)
24
25
  rspec-core (~> 2.7.0)
@@ -36,5 +37,6 @@ DEPENDENCIES
36
37
  ansi
37
38
  em-http-request
38
39
  em-proxy!
40
+ posix-spawn
39
41
  rake
40
42
  rspec
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # EM-Proxy
2
2
 
3
+ [![Build Status](https://travis-ci.org/igrigorik/em-proxy.png?branch=master)](https://travis-ci.org/igrigorik/em-proxy)
4
+
3
5
  EventMachine Proxy DSL for writing high-performance transparent / intercepting proxies in Ruby.
4
6
 
5
7
  - EngineYard tutorial: [Load testing your environment using em-proxy](http://docs.engineyard.com/em-proxy.html)
@@ -14,6 +16,7 @@ EventMachine Proxy DSL for writing high-performance transparent / intercepting p
14
16
  -l, --listen [PORT] Port to listen on
15
17
  -d, --duplex [host:port, ...] List of backends to duplex data to
16
18
  -r, --relay [hostname:port] Relay endpoint: hostname:port
19
+ -s, --socket [filename] Relay endpoint: unix filename
17
20
  -v, --verbose Run in debug mode
18
21
 
19
22
  $> em-proxy -l 8080 -r localhost:8081 -d localhost:8082,localhost:8083 -v
@@ -64,4 +67,4 @@ A schema-free MySQL proof of concept, via an EM-Proxy server:
64
67
 
65
68
  ## License
66
69
 
67
- The MIT License - Copyright (c) 2010 Ilya Grigorik
70
+ The MIT License - Copyright (c) 2010 Ilya Grigorik
@@ -24,6 +24,10 @@ OptionParser.new do |opts|
24
24
  options[:relay] = v.split(":")
25
25
  end
26
26
 
27
+ opts.on("-s", "--socket [filename]", String, "Relay endpoint: unix filename") do |v|
28
+ options[:socket] = v
29
+ end
30
+
27
31
  opts.on("-v", "--verbose", "Run in debug mode") do |v|
28
32
  options[:verbose] = v
29
33
  end
@@ -31,7 +35,11 @@ end.parse!
31
35
 
32
36
 
33
37
  Proxy.start(:host => "0.0.0.0", :port => options[:listen] , :debug => options[:verbose]) do |conn|
34
- conn.server :relay, :host => options[:relay].first, :port => options[:relay].last.to_i
38
+ if options[:socket]
39
+ conn.server :socket, :socket => options[:socket]
40
+ else
41
+ conn.server :relay, :host => options[:relay].first, :port => options[:relay].last.to_i
42
+ end
35
43
 
36
44
  options[:duplex].each_with_index do |backend,i|
37
45
  hostname, port = backend.split(":")
@@ -45,4 +53,8 @@ Proxy.start(:host => "0.0.0.0", :port => options[:listen] , :debug => options[:v
45
53
  conn.on_response do |server, resp|
46
54
  resp if server == :relay
47
55
  end
48
- end
56
+
57
+ conn.on_finish do |server|
58
+ :close if server == :relay
59
+ end
60
+ end
@@ -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.7"
6
+ s.version = "0.1.8"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Ilya Grigorik"]
9
9
  s.email = ["ilya@igvita.com"]
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.add_development_dependency "em-http-request"
19
19
  s.add_development_dependency "ansi"
20
20
  s.add_development_dependency "rake"
21
+ s.add_development_dependency "posix-spawn"
21
22
 
22
23
  s.files = `git ls-files`.split("\n")
23
24
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -43,11 +43,20 @@ module EventMachine
43
43
  # initialize connections to backend servers
44
44
  #
45
45
  def server(name, opts)
46
- srv = EventMachine::bind_connect(opts[:bind_host], opts[:bind_port], opts[:host], opts[:port], EventMachine::ProxyServer::Backend, @debug) do |c|
47
- c.name = name
48
- c.plexer = self
49
- c.proxy_incoming_to(self, 10240) if opts[:relay_server]
46
+ if opts[:socket]
47
+ srv = EventMachine::connect_unix_domain(opts[:socket], EventMachine::ProxyServer::Backend, @debug) do |c|
48
+ c.name = name
49
+ c.plexer = self
50
+ c.proxy_incoming_to(self, 10240) if opts[:relay_server]
51
+ end
52
+ else
53
+ srv = EventMachine::bind_connect(opts[:bind_host], opts[:bind_port], opts[:host], opts[:port], EventMachine::ProxyServer::Backend, @debug) do |c|
54
+ c.name = name
55
+ c.plexer = self
56
+ c.proxy_incoming_to(self, 10240) if opts[:relay_server]
57
+ end
50
58
  end
59
+
51
60
  self.proxy_incoming_to(srv, 10240) if opts[:relay_client]
52
61
 
53
62
  @servers[name] = srv
@@ -1,5 +1,7 @@
1
1
  require 'bundler/setup'
2
2
  require 'em-http'
3
3
  require 'pp'
4
+ require 'tmpdir'
5
+ require 'posix/spawn'
4
6
 
5
7
  require 'em-proxy'
@@ -1,6 +1,7 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Proxy do
4
+ include POSIX::Spawn
4
5
 
5
6
  def failed
6
7
  EventMachine.stop
@@ -68,7 +69,7 @@ describe Proxy do
68
69
  end
69
70
 
70
71
  Proxy.start(:host => "0.0.0.0", :port => 8080) do |conn|
71
- conn.server :bing, :host => "google.com", :port => 80
72
+ conn.server :goog, :host => "google.com", :port => 80
72
73
  conn.server :yhoo, :host => "yahoo.com", :port => 80
73
74
  conn.on_data { |data| data }
74
75
 
@@ -86,6 +87,12 @@ describe Proxy do
86
87
 
87
88
  EventMachine.stop if seen.size == 2
88
89
  end
90
+
91
+ conn.on_finish do |name|
92
+ # keep the connection open if we're still expecting a response
93
+ seen.count == 2 ? :close : :keep
94
+ end
95
+
89
96
  end
90
97
  end
91
98
  end
@@ -164,4 +171,69 @@ describe Proxy do
164
171
  end
165
172
  }.should_not raise_error
166
173
  end
174
+
175
+ context "echo server" do
176
+ before :each do
177
+ @echo_server = File.expand_path("../../spec/support/echo_server.rb", __FILE__)
178
+ end
179
+
180
+ context "with a server listening on a TCP port" do
181
+ before :each do
182
+ @host = '127.0.0.1'
183
+ @port = 4242
184
+ @pid = spawn("ruby #{@echo_server} #{@host} #{@port}")
185
+ sleep 1 # let the server come up
186
+ end
187
+ after :each do
188
+ Process.kill('QUIT', @pid)
189
+ end
190
+ it "should connect to a unix socket" do
191
+ connected = false
192
+ EM.run do
193
+ EventMachine.add_timer(0.1) do
194
+ EventMachine::HttpRequest.new('http://127.0.0.1:8080/').get({:timeout => 1})
195
+ end
196
+ host = @host
197
+ port = @port
198
+ Proxy.start(:host => "0.0.0.0", :port => 8080) do |conn|
199
+ conn.server :local, :host => host, :port => port
200
+ conn.on_connect do |name|
201
+ connected = true
202
+ EventMachine.stop
203
+ end
204
+ end
205
+ end
206
+ connected.should == true
207
+ end
208
+ end
209
+
210
+ context "with a server listening on a unix socket" do
211
+ before :each do
212
+ @socket = File.join(Dir.tmpdir, 'em-proxy.sock')
213
+ @pid = spawn("ruby #{@echo_server} #{@socket}")
214
+ sleep 1 # let the server come up
215
+ end
216
+ after :each do
217
+ Process.kill('QUIT', @pid)
218
+ end
219
+ it "should connect to a unix socket" do
220
+ connected = false
221
+ EM.run do
222
+ EventMachine.add_timer(0.1) do
223
+ EventMachine::HttpRequest.new('http://127.0.0.1:8080/').get({:timeout => 1})
224
+ end
225
+ socket = @socket
226
+ Proxy.start(:host => "0.0.0.0", :port => 8080) do |conn|
227
+ conn.server :local, :socket => socket
228
+ conn.on_connect do |name|
229
+ connected = true
230
+ EventMachine.stop
231
+ end
232
+ end
233
+ end
234
+ connected.should == true
235
+ end
236
+ end
237
+ end
238
+
167
239
  end
@@ -0,0 +1,18 @@
1
+ require 'eventmachine'
2
+
3
+ module EchoServer
4
+ def receive_data data
5
+ send_data ">>>you sent: #{data}"
6
+ close_connection if data =~ /quit/i
7
+ end
8
+ end
9
+
10
+ EventMachine.run do
11
+ if ARGV.count == 2
12
+ EventMachine.start_server ARGV.first, ARGV.last.to_i, EchoServer
13
+ elsif ARGV.count == 1
14
+ EventMachine.start_server ARGV.first, EchoServer
15
+ else
16
+ raise "invalid number of params, expected [server] ([port])"
17
+ end
18
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-13 00:00:00.000000000 Z
12
+ date: 2012-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
@@ -91,6 +91,22 @@ dependencies:
91
91
  - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: posix-spawn
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
94
110
  description: EventMachine Proxy DSL
95
111
  email:
96
112
  - ilya@igvita.com
@@ -101,6 +117,8 @@ extra_rdoc_files: []
101
117
  files:
102
118
  - .gitignore
103
119
  - .rspec
120
+ - .travis.yml
121
+ - CHANGELOG.md
104
122
  - Gemfile
105
123
  - Gemfile.lock
106
124
  - README.md
@@ -128,6 +146,7 @@ files:
128
146
  - spec/balancing_spec.rb
129
147
  - spec/helper.rb
130
148
  - spec/proxy_spec.rb
149
+ - spec/support/echo_server.rb
131
150
  homepage: http://github.com/igrigorik/em-proxy
132
151
  licenses: []
133
152
  post_install_message:
@@ -156,4 +175,5 @@ test_files:
156
175
  - spec/balancing_spec.rb
157
176
  - spec/helper.rb
158
177
  - spec/proxy_spec.rb
178
+ - spec/support/echo_server.rb
159
179
  has_rdoc: