Module: HTTPX::Plugins::Proxy::Socks5::ConnectionMethods

Defined in:
lib/httpx/plugins/proxy/socks5.rb,
sig/plugins/proxy/socks5.rbs

Instance Method Summary collapse

Instance Method Details

#__on_socks5_error(message) ⇒ void

This method returns an undefined value.

Parameters:

  • (string)


131
132
133
134
135
136
# File 'lib/httpx/plugins/proxy/socks5.rb', line 131

def __on_socks5_error(message)
  ex = Error.new(message)
  ex.set_backtrace(caller)
  on_error(ex)
  throw(:called)
end

#__socks5_check_version(version) ⇒ void

This method returns an undefined value.

Parameters:

  • (int)


127
128
129
# File 'lib/httpx/plugins/proxy/socks5.rb', line 127

def __socks5_check_version(version)
  __on_socks5_error("invalid SOCKS version (#{version})") if version != 5
end

#__socks5_on_packet(packet) ⇒ void

This method returns an undefined value.

Parameters:

  • packet (String)


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/httpx/plugins/proxy/socks5.rb', line 96

def __socks5_on_packet(packet)
  case @state
  when :connecting
    version, method = packet.unpack("CC")
    __socks5_check_version(version)
    case method
    when PASSWD
      transition(:authenticating)
      nil
    when NONE
      __on_socks5_error("no supported authorization methods")
    else
      transition(:negotiating)
    end
  when :authenticating
    _, status = packet.unpack("CC")
    return transition(:negotiating) if status == SUCCESS

    __on_socks5_error("socks authentication error: #{status}")
  when :negotiating
    version, reply, = packet.unpack("CC")
    __socks5_check_version(version)
    __on_socks5_error("socks5 negotiation error: #{reply}") unless reply == SUCCESS
    req = @pending.first
    request_uri = req.uri
    @io = ProxySSL.new(@io, request_uri, @options) if request_uri.scheme == "https"
    transition(:connected)
    throw(:called)
  end
end

#__socks5_proxy_connectvoid

This method returns an undefined value.



90
91
92
93
94
# File 'lib/httpx/plugins/proxy/socks5.rb', line 90

def __socks5_proxy_connect
  @parser = SocksParser.new(@write_buffer, @options)
  @parser.on(:packet, &method(:__socks5_on_packet))
  transition(:negotiating)
end

#callObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/httpx/plugins/proxy/socks5.rb', line 32

def call
  super

  return unless @options.proxy && @options.proxy.uri.scheme == "socks5"

  case @state
  when :connecting,
       :negotiating,
       :authenticating
    consume
  end
end

#connecting?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/httpx/plugins/proxy/socks5.rb', line 45

def connecting?
  super || @state == :authenticating || @state == :negotiating
end

#interestsObject



49
50
51
52
53
54
55
# File 'lib/httpx/plugins/proxy/socks5.rb', line 49

def interests
  if @state == :connecting || @state == :authenticating || @state == :negotiating
    return @write_buffer.empty? ? :r : :w
  end

  super
end