Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Use the standard adapter if hostname doesn't match guessed server #250

wants to merge 1 commit into from

2 participants


Fixes #245. The following should work now:

$ ruby-whois -h

The guessed server is also still used if the hostname happens to match:

$ ruby-whois -h

I'm actually not sure about this patch. While the final solution is correct, I'm actually considering whether it's a better idea to reset the adapter to the Standard adapter instead of implementing an if condition in every single adapter.


What about updating lookup in the Base adapter?

def lookup(string)
  buffer_start do |buffer|
    request(options[:host] ? string : formatted_string(string)), buffer)

With formatted_string returning string by default, but defined for adapters that need a different format - i.e. "=#{string}" in the case of Verisign. That way, the referral logic for each adapter can still be used.


Nevermind, that was a bad idea. You're right - it'd be better to just fall back to Standard if the custom hostname doesn't match the guessed server. That would handle the referrals too.

@linrock linrock closed this

Here's a general solution using the Standard adapter. Hopefully this is on the right track.

@linrock linrock reopened this

There are no tests attached to this patch, but I believe because this is a work-in-progress prototype.

I'm not a big fan of this implementation. It has some drawbacks.

  1. If you pass an host along with an unsupported TLD, it will fail. For example

    ruby-whois -h
  2. It will fail if the object is not recognized. For example, if you try to pass a formatted query.

I have to think a little bit about a possible solution. In my opinion, a possible approach would be to change the .guess method itself to return a standard adapter whenever an host is passed. But this is just an hypothesis.

The best approach is probably to write some test cases and use TDD to satisfy the requirements.

@weppos weppos added enhancement and removed enhancement labels
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 1 deletion.
  1. +1 −1  lib/whois/client.rb
  2. +15 −0 lib/whois/server.rb
2  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)
15 lib/whois/server.rb
@@ -245,6 +245,21 @@ def self.guess(string)
+ # 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] && != settings[:host]
+ return, server.allocation,, server.options)
+ end
+ server
+ end
def self.camelize(string)
Something went wrong with that request. Please try again.