mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-06 00:03:36 -04:00
add "http://" scheme to ENV['http_proxy'] value if missing
This allows: http_proxy=localhost:8888 ruby myscript.rb Omitting the scheme is already supported by curl, and this matches that behavior.
This commit is contained in:
parent
4488ce523e
commit
cff8dded75
@ -80,7 +80,13 @@ module Faraday
|
||||
@headers.update(options.headers) if options.headers
|
||||
|
||||
@proxy = nil
|
||||
proxy(options.fetch(:proxy) { ENV['http_proxy'] })
|
||||
proxy(options.fetch(:proxy) {
|
||||
uri = ENV['http_proxy']
|
||||
if uri && !uri.empty?
|
||||
uri = 'http://' + uri if uri !~ /^http/i
|
||||
uri
|
||||
end
|
||||
})
|
||||
|
||||
yield self if block_given?
|
||||
|
||||
|
@ -287,6 +287,42 @@ class TestConnection < Faraday::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def test_proxy_accepts_env_without_scheme
|
||||
with_env 'http_proxy', "localhost:8888" do
|
||||
uri = Faraday::Connection.new.proxy[:uri]
|
||||
assert_equal 'localhost', uri.host
|
||||
assert_equal 8888, uri.port
|
||||
end
|
||||
end
|
||||
|
||||
def test_no_proxy_from_env
|
||||
with_env 'http_proxy', nil do
|
||||
conn = Faraday::Connection.new
|
||||
assert_equal nil, conn.proxy
|
||||
end
|
||||
end
|
||||
|
||||
def test_no_proxy_from_blank_env
|
||||
with_env 'http_proxy', '' do
|
||||
conn = Faraday::Connection.new
|
||||
assert_equal nil, conn.proxy
|
||||
end
|
||||
end
|
||||
|
||||
def test_proxy_doesnt_accept_uppercase_env
|
||||
with_env 'HTTP_PROXY', "http://localhost:8888/" do
|
||||
conn = Faraday::Connection.new
|
||||
assert_nil conn.proxy
|
||||
end
|
||||
end
|
||||
|
||||
def test_proxy_requires_uri
|
||||
conn = Faraday::Connection.new
|
||||
assert_raises ArgumentError do
|
||||
conn.proxy :uri => :bad_uri, :user => 'rick'
|
||||
end
|
||||
end
|
||||
|
||||
def test_dups_connection_object
|
||||
conn = Faraday::Connection.new 'http://sushi.com/foo',
|
||||
:ssl => { :verify => :none },
|
||||
|
Loading…
x
Reference in New Issue
Block a user