Skip to content

Commit

Permalink
Expose local socket config in EM::HTTP and ilk
Browse files Browse the repository at this point in the history
  • Loading branch information
hakanensari committed May 2, 2012
1 parent 371ad26 commit 5b91734
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/faraday/adapter/em_http.rb
Expand Up @@ -51,6 +51,15 @@ def configure_proxy(options, env)
end end
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) def configure_timeout(options, env)
timeout, open_timeout = request_options(env).values_at(:timeout, :open_timeout) timeout, open_timeout = request_options(env).values_at(:timeout, :open_timeout)
options[:connect_timeout] = options[:inactivity_timeout] = timeout options[:connect_timeout] = options[:inactivity_timeout] = timeout
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/adapter/em_synchrony.rb
Expand Up @@ -19,7 +19,7 @@ def self.setup_parallel_manager(options = {})


def call(env) def call(env)
super 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 http_method = env[:method].to_s.downcase.to_sym


Expand Down
6 changes: 6 additions & 0 deletions test/adapters/em_http_test.rb
Expand Up @@ -10,5 +10,11 @@ def adapter() :em_http end
undef :test_timeout undef :test_timeout
end 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
end end
6 changes: 6 additions & 0 deletions test/adapters/em_synchrony_test.rb
Expand Up @@ -10,5 +10,11 @@ def adapter() :em_synchrony end
undef :test_timeout undef :test_timeout
end 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 unless RUBY_VERSION < '1.9' or (defined? RUBY_ENGINE and 'jruby' == RUBY_ENGINE)
end end
4 changes: 4 additions & 0 deletions test/live_server.rb
Expand Up @@ -35,6 +35,10 @@ class FaradayTestServer < Sinatra::Base
[200, { 'Set-Cookie' => 'one, two' }, ''] [200, { 'Set-Cookie' => 'one, two' }, '']
end end


get '/who-am-i' do
request.env['REMOTE_ADDR']
end

get '/slow' do get '/slow' do
sleep 10 sleep 10
[200, {}, 'ok'] [200, {}, 'ok']
Expand Down

0 comments on commit 5b91734

Please sign in to comment.