From c4665c9e658bef7026610abef3f8f7e25b6cf378 Mon Sep 17 00:00:00 2001 From: Evgeniy Serykh Date: Sat, 19 Mar 2022 15:39:19 +0700 Subject: [PATCH] Add Ruby 3.1 support for socks --- lib/uri/socks.rb | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/uri/socks.rb b/lib/uri/socks.rb index 4cf050b..1b8f35a 100644 --- a/lib/uri/socks.rb +++ b/lib/uri/socks.rb @@ -1,18 +1,32 @@ -require "uri/generic" +require 'uri/generic' module URI - class SOCKS < Generic + class Socks < Generic DEFAULT_PORT = 1080 COMPONENT = [:scheme, :userinfo, :host, :port, :query].freeze + + def self.build(args) + tmp = Util.make_components_hash(self, args) + super(tmp) + end + end + + class Socks4 < Socks end - @@schemes["SOCKS"] = SOCKS - @@schemes["SOCKS5"] = SOCKS - class SOCKS4 < SOCKS + class Socks4A < Socks end - @@schemes["SOCKS4"] = SOCKS4 - class SOCKS4A < SOCKS + mapping = { + 'SOCKS' => Socks, + 'SOCKS5' => Socks, + 'SOCKS4' => Socks4, + 'SOCKS4A' => Socks4A + } + if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.1.0') + mapping.each { |scheme, class_name| register_scheme scheme, class_name } + else + mapping.each { |scheme, class_name| @@schemes[scheme] = class_name } end - @@schemes["SOCKS4A"] = SOCKS4A end +