mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-09 00:04:39 -04:00
Merge pull request #80 from whomwah/master
Add support for http_proxy environment variable
This commit is contained in:
commit
1e53edf46a
@ -33,7 +33,8 @@ module Faraday
|
|||||||
@parallel_manager = options[:parallel]
|
@parallel_manager = options[:parallel]
|
||||||
|
|
||||||
self.url_prefix = url if url
|
self.url_prefix = url if url
|
||||||
proxy(options[:proxy])
|
|
||||||
|
proxy(options.fetch(:proxy) { ENV['http_proxy'] })
|
||||||
|
|
||||||
@params.update options[:params] if options[:params]
|
@params.update options[:params] if options[:params]
|
||||||
@headers.update options[:headers] if options[:headers]
|
@headers.update options[:headers] if options[:headers]
|
||||||
|
@ -1,6 +1,17 @@
|
|||||||
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||||
|
|
||||||
class TestConnection < Faraday::TestCase
|
class TestConnection < Faraday::TestCase
|
||||||
|
|
||||||
|
def with_proxy_env(proxy)
|
||||||
|
old_proxy = ENV['http_proxy']
|
||||||
|
ENV['http_proxy'] = proxy
|
||||||
|
begin
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
ENV['http_proxy'] = old_proxy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_initialize_parses_host_out_of_given_url
|
def test_initialize_parses_host_out_of_given_url
|
||||||
conn = Faraday::Connection.new "http://sushi.com"
|
conn = Faraday::Connection.new "http://sushi.com"
|
||||||
assert_equal 'sushi.com', conn.host
|
assert_equal 'sushi.com', conn.host
|
||||||
@ -202,31 +213,46 @@ class TestConnection < Faraday::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_proxy_accepts_string
|
def test_proxy_accepts_string
|
||||||
conn = Faraday::Connection.new
|
with_proxy_env "http://duncan.proxy.com:80" do
|
||||||
conn.proxy 'http://proxy.com'
|
conn = Faraday::Connection.new
|
||||||
assert_equal 'proxy.com', conn.proxy[:uri].host
|
conn.proxy 'http://proxy.com'
|
||||||
assert_equal [:uri], conn.proxy.keys
|
assert_equal 'proxy.com', conn.proxy[:uri].host
|
||||||
|
assert_equal [:uri], conn.proxy.keys
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_proxy_accepts_uri
|
def test_proxy_accepts_uri
|
||||||
conn = Faraday::Connection.new
|
with_proxy_env "http://duncan.proxy.com:80" do
|
||||||
conn.proxy Addressable::URI.parse('http://proxy.com')
|
conn = Faraday::Connection.new
|
||||||
assert_equal 'proxy.com', conn.proxy[:uri].host
|
conn.proxy Addressable::URI.parse('http://proxy.com')
|
||||||
assert_equal [:uri], conn.proxy.keys
|
assert_equal 'proxy.com', conn.proxy[:uri].host
|
||||||
|
assert_equal [:uri], conn.proxy.keys
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_proxy_accepts_hash_with_string_uri
|
def test_proxy_accepts_hash_with_string_uri
|
||||||
conn = Faraday::Connection.new
|
with_proxy_env "http://duncan.proxy.com:80" do
|
||||||
conn.proxy :uri => 'http://proxy.com', :user => 'rick'
|
conn = Faraday::Connection.new
|
||||||
assert_equal 'proxy.com', conn.proxy[:uri].host
|
conn.proxy :uri => 'http://proxy.com', :user => 'rick'
|
||||||
assert_equal 'rick', conn.proxy[:user]
|
assert_equal 'proxy.com', conn.proxy[:uri].host
|
||||||
|
assert_equal 'rick', conn.proxy[:user]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_proxy_accepts_hash
|
def test_proxy_accepts_hash
|
||||||
conn = Faraday::Connection.new
|
with_proxy_env "http://duncan.proxy.com:80" do
|
||||||
conn.proxy :uri => Addressable::URI.parse('http://proxy.com'), :user => 'rick'
|
conn = Faraday::Connection.new
|
||||||
assert_equal 'proxy.com', conn.proxy[:uri].host
|
conn.proxy :uri => Addressable::URI.parse('http://proxy.com'), :user => 'rick'
|
||||||
assert_equal 'rick', conn.proxy[:user]
|
assert_equal 'proxy.com', conn.proxy[:uri].host
|
||||||
|
assert_equal 'rick', conn.proxy[:user]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_proxy_accepts_http_env
|
||||||
|
with_proxy_env "http://duncan.proxy.com:80" do
|
||||||
|
conn = Faraday::Connection.new
|
||||||
|
assert_equal 'duncan.proxy.com', conn.proxy[:uri].host
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_proxy_requires_uri
|
def test_proxy_requires_uri
|
||||||
|
Loading…
x
Reference in New Issue
Block a user