Permalink
Browse files

Expose local socket config in EM::HTTP and ilk

  • Loading branch information...
1 parent 371ad26 commit 5b91734495db7b9febef56fbdf07d6389c0ab423 @hakanensari hakanensari committed May 2, 2012
@@ -51,6 +51,15 @@ def configure_proxy(options, env)
end
end
+ def configure_socket(options, env)
+ if bind = request_options(env)[:bind]
+ options[:bind] = {
+ :host => bind[:host],
+ :port => bind[:port]
+ }
+ end
+ end
+
def configure_timeout(options, env)
timeout, open_timeout = request_options(env).values_at(:timeout, :open_timeout)
options[:connect_timeout] = options[:inactivity_timeout] = timeout
@@ -19,7 +19,7 @@ def self.setup_parallel_manager(options = {})
def call(env)
super
- request = EventMachine::HttpRequest.new(URI::parse(env[:url].to_s), connection_config(env)) # end
+ request = EventMachine::HttpRequest.new(URI::parse(env[:url].to_s), connection_config(env))
http_method = env[:method].to_s.downcase.to_sym
@@ -10,5 +10,11 @@ def adapter() :em_http end
undef :test_timeout
end
+ def test_binds_local_socket
+ host = '1.2.3.4'
+ conn = create_connection :request => { :bind => { :host => host } }
+ #puts conn.get('/who-am-i').body
+ assert_equal host, conn.options[:bind][:host]
+ end
end
end
@@ -10,5 +10,11 @@ def adapter() :em_synchrony end
undef :test_timeout
end
+ def test_binds_local_socket
+ host = '1.2.3.4'
+ conn = create_connection :request => { :bind => { :host => host } }
+ #put conn.get('/who-am-i').body
+ assert_equal host, conn.options[:bind][:host]
+ end
end unless RUBY_VERSION < '1.9' or (defined? RUBY_ENGINE and 'jruby' == RUBY_ENGINE)
end
View
@@ -35,6 +35,10 @@ class FaradayTestServer < Sinatra::Base
[200, { 'Set-Cookie' => 'one, two' }, '']
end
+ get '/who-am-i' do
+ request.env['REMOTE_ADDR']
+ end
+
get '/slow' do
sleep 10
[200, {}, 'ok']

0 comments on commit 5b91734

Please sign in to comment.