Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Open
wants to merge 1 commit into from

2 participants

@linrock

Fixes #245. The following should work now:

$ ruby-whois surface.net -h whois.tucows.com

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

$ ruby-whois 130.66.76.222 -h whois.arin.net
@weppos
Owner

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.

@linrock

What about updating lookup in the Base adapter?

def lookup(string)
  buffer_start do |buffer|
    request(options[:host] ? string : formatted_string(string))
    Whois::Record.new(self, buffer)
  end
end

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.

@linrock

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
@linrock

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

@linrock linrock reopened this
@weppos
Owner

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 google.va -h whois.holygrail.va
    
  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
View
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)
@server.configure(settings)
@server.lookup(string)
end
View
15 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)
Something went wrong with that request. Please try again.