lib/httpx/plugins/proxy/socks5.rb in httpx-0.0.5 vs lib/httpx/plugins/proxy/socks5.rb in httpx-0.1.0
- old
+ new
@@ -43,23 +43,23 @@
case method
when PASSWD
transition(:authenticating)
return
when NONE
- on_error_response("no supported authorization methods")
+ on_socks_error("no supported authorization methods")
else
transition(:negotiating)
end
when :authenticating
version, status = packet.unpack("CC")
check_version(version)
return transition(:negotiating) if status == SUCCESS
- on_error_response("socks authentication error: #{status}")
+ on_socks_error("socks authentication error: #{status}")
when :negotiating
version, reply, = packet.unpack("CC")
check_version(version)
- return on_error_response("socks5 negotiation error: #{reply}") unless reply == SUCCESS
+ on_socks_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)
@@ -84,25 +84,25 @@
@write_buffer << Packet.connect(request_uri)
when :connected
return unless @state == :negotiating
@parser = nil
end
- log(level: 1, label: "SOCKS5: ") { "#{nextstate}: #{@write_buffer.to_s.inspect}" }
+ log(level: 1, label: "SOCKS5: ") { "#{nextstate}: #{@write_buffer.to_s.inspect}" } unless nextstate == :open
super
end
def check_version(version)
- raise Error, "invalid SOCKS version (#{version})" if version != 5
+ on_socks_error("invalid SOCKS version (#{version})") if version != 5
end
- def on_error_response(error)
- response = ErrorResponse.new(Error.new(error), 0, @options)
- until @pending.empty?
- req, _ = @pending.shift
- emit(:response, req, response)
- end
+ def on_socks_error(message)
+ ex = Error.new(message)
+ ex.set_backtrace(caller)
+ on_error(ex)
+ throw(:called)
end
end
+
Parameters.register("socks5", Socks5ProxyChannel)
class SocksParser
include Callbacks