lib/httpx/plugins/proxy/socks5.rb in httpx-0.0.2 vs lib/httpx/plugins/proxy/socks5.rb in httpx-0.0.3
- old
+ new
@@ -15,10 +15,20 @@
SUCCESS = 0
Error = Class.new(Error)
class Socks5ProxyChannel < ProxyChannel
+ def call
+ super
+ case @state
+ when :connecting,
+ :negotiating,
+ :authenticating
+ consume
+ end
+ end
+
private
def proxy_connect
@parser = SocksParser.new(@write_buffer, @options)
@parser.on(:packet, &method(:on_packet))
@@ -49,32 +59,32 @@
check_version(version)
return on_error_response("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(:open)
+ transition(:connected)
throw(:called)
end
end
def transition(nextstate)
case nextstate
when :connecting
return unless @state == :idle
@io.connect
- return if @io.closed?
+ return unless @io.connected?
@write_buffer << Packet.negotiate(@parameters)
proxy_connect
when :authenticating
return unless @state == :connecting
@write_buffer << Packet.authenticate(@parameters)
when :negotiating
return unless @state == :connecting || @state == :authenticating
req, _ = @pending.first
request_uri = req.uri
@write_buffer << Packet.connect(request_uri)
- when :open
+ when :connected
return unless @state == :negotiating
@parser = nil
end
log(1, "SOCKS5: ") { "#{nextstate}: #{@write_buffer.to_s.inspect}" }
super
@@ -83,10 +93,10 @@
def check_version(version)
raise Error, "invalid SOCKS version (#{version})" if version != 5
end
def on_error_response(error)
- response = ErrorResponse.new(error, 0)
+ response = ErrorResponse.new(Error.new(error), 0, @options)
until @pending.empty?
req, _ = @pending.shift
emit(:response, req, response)
end
end