Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add em-proxy bin script for easy proxy debugging & relay use cases

  • Loading branch information...
commit 5cf7f5c0eeacc97c11cbd4e85ebec0eaa861775e 1 parent d9252f9
Ilya Grigorik authored
Showing with 58 additions and 8 deletions.
  1. +9 −6 README.rdoc
  2. +0 −1  VERSION
  3. +48 −0 bin/em-proxy
  4. +1 −1  em-proxy.gemspec
15 README.rdoc
View
@@ -7,14 +7,17 @@ EventMachine Proxy DSL for writing high-performance transparent / intercepting p
== Getting started
- # install & configure gemcutter repos
- gem update --system
- gem install gemcutter
- gem tumble
+ $> gem install em-proxy
+ $> em-proxy
+ Usage: em-proxy [options]
+ -l, --listen [PORT] Port to listen on
+ -d, --duplex [host:port, ...] List of backends to duplex data to
+ -r, --relay [hostname:port] Relay endpoint: hostname:port
+ -v, --verbose Run in debug mode
- gem install em-proxy
+ $> em-proxy -l 8080 -r localhost:8081 -d localhost:8082,localhost:8083 -v
- irb:0> require 'em-proxy'
+The above will start em-proxy on port 8080, relay and respond with data from port 8081, and also (optional) duplicate all traffic to ports 8082 and 8083 (and discard their responses).
== Simple port forwarding proxy
1  VERSION
View
@@ -1 +0,0 @@
-0.1.4
48 bin/em-proxy
View
@@ -0,0 +1,48 @@
+#!/usr/bin/env ruby
+
+lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
+$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
+
+require 'em-proxy'
+require 'optparse'
+
+ARGV << '--help' if ARGV.empty?
+
+options = {}
+OptionParser.new do |opts|
+ opts.banner = "Usage: em-proxy [options]"
+
+ opts.on("-l", "--listen [PORT]", Integer, "Port to listen on") do |v|
+ options[:listen] = v
+ end
+
+ opts.on("-d", "--duplex [host:port, ...]", Array, "List of backends to duplex data to") do |v|
+ options[:duplex] = v
+ end
+
+ opts.on("-r", "--relay [hostname:port]", String, "Relay endpoint: hostname:port") do |v|
+ options[:relay] = v.split(":")
+ end
+
+ opts.on("-v", "--verbose", "Run in debug mode") do |v|
+ options[:verbose] = v
+ end
+end.parse!
+
+
+Proxy.start(:host => "0.0.0.0", :port => options[:listen] , :debug => options[:verbose]) do |conn|
+ conn.server :relay, :host => options[:relay].first, :port => options[:relay].last.to_i
+
+ options[:duplex].each_with_index do |backend,i|
+ hostname, port = backend.split(":")
+ conn.server "backend_#{i}".intern, :host => hostname, :port => port.to_i
+ end if options[:duplex]
+
+ conn.on_data do |data|
+ data
+ end
+
+ conn.on_response do |server, resp|
+ resp if server == :relay
+ end
+end
2  em-proxy.gemspec
View
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
Gem::Specification.new do |s|
s.name = "em-proxy"
- s.version = "0.1.4"
+ s.version = "0.1.5"
s.platform = Gem::Platform::RUBY
s.authors = ["Ilya Grigorik"]
s.email = ["ilya@igvita.com"]
Please sign in to comment.
Something went wrong with that request. Please try again.