Class: Telegram::Bot::Adapters::Socks5

Inherits:
Faraday::Adapter::NetHttp
  • Object
show all
Defined in:
lib/telegram/bot/adapters/socks5.rb

Instance Method Summary collapse

Instance Method Details

#net_http_connection(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/telegram/bot/adapters/socks5.rb', line 8

def net_http_connection(env)
  if proxy = env[:request][:proxy]
    if proxy[:socks]
      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)
    else
      Net::HTTP::Proxy(proxy[:uri].host, proxy[:uri].port, proxy[:uri].user, proxy[:uri].password)
    end
  else
    Net::HTTP
  end.new(env[:url].host, env[:url].port)
end