Class: MonoVM::Whois::Transport::RdapHttp
- 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
-
#open_timeout ⇒ Object
readonly
Returns the value of attribute open_timeout.
-
#read_timeout ⇒ Object
readonly
Returns the value of attribute read_timeout.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
-
#verify_ssl ⇒ Object
readonly
Returns the value of attribute verify_ssl.
Instance Method Summary collapse
- #fetch(query:, endpoint:) ⇒ Response
-
#initialize(open_timeout: DEFAULT_OPEN_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT, verify_ssl: true, user_agent: nil) ⇒ RdapHttp
constructor
A new instance of RdapHttp.
- #supports?(endpoint) ⇒ Boolean
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.
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_timeout ⇒ Object (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_timeout ⇒ Object (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_agent ⇒ Object (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_ssl ⇒ Object (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
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
48 49 50 |
# File 'lib/monovm/whois/transport/rdap_http.rb', line 48 def supports?(endpoint) endpoint.http? end |