Skip to content

Commit

Permalink
break up #proxy_class into #http_proxy and #socks_proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed Jun 13, 2019
1 parent c7f5bb3 commit 347e799
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions lib/faraday/adapter/net_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,28 @@ def with_net_http_connection(env)
end

def net_http_connection(env)
klass = if (proxy = env[:request][:proxy])
proxy_class(proxy)
else
proxy = env[:request][:proxy]
klass = if proxy.nil?
Net::HTTP
elsif proxy.uri.scheme != 'socks'
http_proxy(proxy)
else
socks_proxy(proxy)
end
port = env[:url].port || (env[:url].scheme == 'https' ? 443 : 80)
klass.new(env[:url].hostname, port)
end

def proxy_class(proxy)
if proxy.uri.scheme != "socks"
return Net::HTTP::Proxy(
proxy[:uri].host,
proxy[:uri].port,
proxy[:uri].user,
proxy[:uri].password,
)
end
def http_proxy(proxy)
Net::HTTP::Proxy(
proxy[:uri].host,
proxy[:uri].port,
proxy[:uri].user,
proxy[:uri].password,
)
end

def socks_proxy(proxy)
TCPSocket.socks_username = proxy[:user] if proxy[:user]
TCPSocket.socks_password = proxy[:password] if proxy[:password]
Net::HTTP::SOCKSProxy(proxy[:uri].host, proxy[:uri].port)
Expand Down

0 comments on commit 347e799

Please sign in to comment.