module HTTPX::Plugins::Proxy::Socks4::Packet

  1. lib/httpx/plugins/proxy/socks4.rb

Methods

Public Instance

  1. connect

Public Instance methods

connect(parameters, uri)
[show source]
    # File lib/httpx/plugins/proxy/socks4.rb
111 def connect(parameters, uri)
112   packet = [VERSION, CONNECT, uri.port].pack("CCn")
113 
114   case parameters.uri.scheme
115   when "socks4"
116     socks_host = uri.host
117     begin
118       ip = IPAddr.new(socks_host)
119       packet << ip.hton
120     rescue IPAddr::InvalidAddressError
121       socks_host = Resolv.getaddress(socks_host)
122       retry
123     end
124     packet << [parameters.username].pack("Z*")
125   when "socks4a"
126     packet << "\x0\x0\x0\x1" << [parameters.username].pack("Z*") << uri.host << "\x0"
127   end
128   packet
129 end