Method: HTTPX::Plugins::Proxy::Socks5::Packet.connect

Defined in:
lib/httpx/plugins/proxy/socks5.rb

.connect(uri) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/httpx/plugins/proxy/socks5.rb', line 175

def connect(uri)
  packet = [VERSION, CONNECT, 0].pack("C*")
  begin
    ip = IPAddr.new(uri.host)

    ipcode = ip.ipv6? ? IPV6 : IPV4

    packet << [ipcode].pack("C") << ip.hton
  rescue IPAddr::InvalidAddressError
    packet << [DOMAIN, uri.host.bytesize, uri.host].pack("CCA*")
  end
  packet << [uri.port].pack("n")
  packet
end