Permalink
Browse files

Merge pull request #25 from kostya/master

add bind to proxy
  • Loading branch information...
2 parents e386de7 + eee702d commit cc3b692f9f853be914350cd14641b0def9955eb7 @igrigorik committed Apr 30, 2012
Showing with 10 additions and 5 deletions.
  1. +1 −1 Gemfile
  2. +3 −1 Gemfile.lock
  3. +1 −0 em-proxy.gemspec
  4. +4 −2 examples/http_proxy.rb
  5. +1 −1 lib/em-proxy/connection.rb
View
@@ -1,3 +1,3 @@
source "http://rubygems.org"
-gemspec
+gemspec
View
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- em-proxy (0.1.5)
+ em-proxy (0.1.6)
eventmachine
GEM
@@ -19,6 +19,7 @@ GEM
eventmachine
eventmachine (1.0.0.beta.4)
http_parser.rb (0.5.3)
+ rake (0.9.2.2)
rspec (2.7.0)
rspec-core (~> 2.7.0)
rspec-expectations (~> 2.7.0)
@@ -35,4 +36,5 @@ DEPENDENCIES
ansi
em-http-request
em-proxy!
+ rake
rspec
View
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
s.add_development_dependency "rspec"
s.add_development_dependency "em-http-request"
s.add_development_dependency "ansi"
+ s.add_development_dependency "rake"
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -2,8 +2,9 @@
require 'http/parser' # gem install http_parser.rb
require 'uuid' # gem install uuid
-# > ruby em-proxy-http.rb
+# > ruby http_proxy.rb
# > curl --proxy localhost:9889 www.google.com
+# > curl --proxy x.x.x.x:9889 www.google.com - bind ip example
host = "0.0.0.0"
port = 9889
@@ -17,7 +18,8 @@
puts "New session: #{session} (#{h.inspect})"
host, port = h['Host'].split(':')
- conn.server session, :host => host, :port => (port || 80)
+ conn.server session, :host => host, :port => (port || 80) #, :bind_host => conn.peer[0] - # for bind ip
+
conn.relay_to_servers @buffer
@buffer.clear
@@ -43,7 +43,7 @@ def relay_to_servers(processed)
# initialize connections to backend servers
#
def server(name, opts)
- srv = EventMachine::connect(opts[:host], opts[:port], EventMachine::ProxyServer::Backend, @debug) do |c|
+ srv = EventMachine::bind_connect(opts[:bind_host], opts[:bind_port], opts[:host], opts[:port], EventMachine::ProxyServer::Backend, @debug) do |c|
c.name = name
c.plexer = self
c.proxy_incoming_to(self, 10240) if opts[:relay_server]

0 comments on commit cc3b692

Please sign in to comment.