From 9385230e9818208d6429aa9fa57c68c79a9b0ab9 Mon Sep 17 00:00:00 2001 From: Linmiao Xu Date: Sun, 11 Aug 2013 16:18:03 -0700 Subject: [PATCH] Fallback to the standard adapter if host doesn't match. --- lib/whois/client.rb | 2 +- lib/whois/server.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/whois/client.rb b/lib/whois/client.rb index c9adf7278..34e237277 100644 --- a/lib/whois/client.rb +++ b/lib/whois/client.rb @@ -89,7 +89,7 @@ def initialize(settings = {}) def lookup(object) string = object.to_s.downcase Timeout::timeout(timeout) do - @server = Server.guess(string) + @server = Server.guess_with_fallback(string, settings) @server.configure(settings) @server.lookup(string) end diff --git a/lib/whois/server.rb b/lib/whois/server.rb index 961fe702a..b85423e05 100644 --- a/lib/whois/server.rb +++ b/lib/whois/server.rb @@ -245,6 +245,21 @@ def self.guess(string) end + # Try to guess the right server, or use the Standard adapter if necessary. + # + # @param [String] string + # @param [Hash] settings Hash of settings originally sent to the client. + # @return [Whois::Server::Adapters::Base] + # + def self.guess_with_fallback(string, settings) + server = guess(string) + if settings[:host] && server.host != settings[:host] + return Adapters::Standard.new(server.type, server.allocation, server.host, server.options) + end + server + end + + private def self.camelize(string)