Class: MonoVM::Whois::Transport::RdapHttp

Inherits:
Base
  • Object
show all
Defined in:
lib/monovm/whois/transport/rdap_http.rb

Overview

RDAP over HTTPS (RFC 7480-7483).

RDAP is the reason this library can be confident where a WHOIS-only one has to guess. A registered domain comes back as JSON with an objectClassName; an unregistered one comes back as HTTP 404 with an errorCode of 404. Both are answers, so both are returned as a Response for the rules to read.

What is not an answer gets raised instead: 401/403/405/406/429 mean the server refused us, and 5xx means it broke. Handing those bodies back would let an error page be pattern-matched into "available".

Constant Summary collapse

DEFAULT_OPEN_TIMEOUT =
10.0
DEFAULT_READ_TIMEOUT =
30.0
MAX_REDIRECTS =
3
REFUSAL_STATUSES =

404 carries the "no such domain" answer, so it is deliberately absent.

[401, 403, 405, 406, 429].freeze
ACCEPT =
"application/rdap+json, application/json;q=0.9, */*;q=0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(open_timeout: DEFAULT_OPEN_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT, verify_ssl: true, user_agent: nil) ⇒ RdapHttp

Returns a new instance of RdapHttp.

Parameters:

  • (defaults to: true)

    verify TLS certificates. Defaults to true. A handful of registry endpoints do serve broken chains; those deployments can opt out explicitly rather than everyone losing the guarantee silently.



38
39
40
41
42
43
44
45
46
# File 'lib/monovm/whois/transport/rdap_http.rb', line 38

def initialize(open_timeout: DEFAULT_OPEN_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT,
               verify_ssl: true, user_agent: nil)
  @open_timeout = open_timeout
  @read_timeout = read_timeout
  @verify_ssl = verify_ssl
  @user_agent = user_agent ||
                "monovm-whois-ruby/#{MonoVM::Whois::VERSION} (+https://github.com/monovm/whois-ruby)"
  super()
end

Instance Attribute Details

#open_timeoutObject (readonly)

Returns the value of attribute open_timeout.



32
33
34
# File 'lib/monovm/whois/transport/rdap_http.rb', line 32

def open_timeout
  @open_timeout
end

#read_timeoutObject (readonly)

Returns the value of attribute read_timeout.



32
33
34
# File 'lib/monovm/whois/transport/rdap_http.rb', line 32

def read_timeout
  @read_timeout
end

#user_agentObject (readonly)

Returns the value of attribute user_agent.



32
33
34
# File 'lib/monovm/whois/transport/rdap_http.rb', line 32

def user_agent
  @user_agent
end

#verify_sslObject (readonly)

Returns the value of attribute verify_ssl.



32
33
34
# File 'lib/monovm/whois/transport/rdap_http.rb', line 32

def verify_ssl
  @verify_ssl
end

Instance Method Details

#fetch(query:, endpoint:) ⇒ Response

Raises:

Returns:



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/monovm/whois/transport/rdap_http.rb', line 54

def fetch(query:, endpoint:)
  url = URI.parse(endpoint.url_for(query))
  (response, elapsed) = measure { request(url, endpoint) }

  Response.new(
    body: response.body.to_s,
    endpoint: endpoint,
    query: query,
    status: Integer(response.code),
    elapsed: elapsed
  )
rescue URI::InvalidURIError => e
  raise ConnectionError, "cannot build an RDAP URL for #{query}: #{e.message}"
end

#supports?(endpoint) ⇒ Boolean

Returns:



48
49
50
# File 'lib/monovm/whois/transport/rdap_http.rb', line 48

def supports?(endpoint)
  endpoint.http?
end