Class: MonoVM::Whois::Transport::WhoisSocket
- Defined in:
- lib/monovm/whois/transport/whois_socket.rb
Overview
WHOIS over TCP port 43 (RFC 3912).
The protocol is as thin as protocols get: connect, send the query and a CRLF, read until the server closes. What needs care is everything around that — a registry that accepts the connection and then never answers, one that sends half a record and hangs up, one that replies in Latin-1.
Constant Summary collapse
- DEFAULT_CONNECT_TIMEOUT =
10.0- DEFAULT_READ_TIMEOUT =
15.0- CHUNK_SIZE =
16_384- FALLBACK_ENCODING =
Registries that answer in Latin-1. Trying UTF-8 first and falling back keeps accented registrant names readable rather than replacing them with U+FFFD.
Encoding::ISO_8859_1
- CONNECT_TIMEOUTS =
IO::TimeoutError only exists from Ruby 3.2. Naming it directly in a rescue clause would raise NameError on 3.1 at the moment an exception occurred — turning a timeout into a crash — so the list is built once, here.
[ Errno::ETIMEDOUT, (IO::TimeoutError if defined?(IO::TimeoutError)) ].compact.freeze
Instance Attribute Summary collapse
-
#connect_timeout ⇒ Object
readonly
Returns the value of attribute connect_timeout.
-
#read_timeout ⇒ Object
readonly
Returns the value of attribute read_timeout.
Instance Method Summary collapse
- #fetch(query:, endpoint:) ⇒ Response
-
#initialize(connect_timeout: DEFAULT_CONNECT_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT) ⇒ WhoisSocket
constructor
A new instance of WhoisSocket.
- #supports?(endpoint) ⇒ Boolean
Constructor Details
#initialize(connect_timeout: DEFAULT_CONNECT_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT) ⇒ WhoisSocket
Returns a new instance of WhoisSocket.
35 36 37 38 39 |
# File 'lib/monovm/whois/transport/whois_socket.rb', line 35 def initialize(connect_timeout: DEFAULT_CONNECT_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT) @connect_timeout = connect_timeout @read_timeout = read_timeout super() end |
Instance Attribute Details
#connect_timeout ⇒ Object (readonly)
Returns the value of attribute connect_timeout.
33 34 35 |
# File 'lib/monovm/whois/transport/whois_socket.rb', line 33 def connect_timeout @connect_timeout end |
#read_timeout ⇒ Object (readonly)
Returns the value of attribute read_timeout.
33 34 35 |
# File 'lib/monovm/whois/transport/whois_socket.rb', line 33 def read_timeout @read_timeout end |
Instance Method Details
#fetch(query:, endpoint:) ⇒ Response
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/monovm/whois/transport/whois_socket.rb', line 47 def fetch(query:, endpoint:) body, elapsed = measure { exchange(query, endpoint) } if body.strip.empty? raise EmptyResponseError, "#{endpoint.host} closed the connection without answering for #{query}" end Response.new(body: body, endpoint: endpoint, query: query, elapsed: elapsed) end |
#supports?(endpoint) ⇒ Boolean
41 42 43 |
# File 'lib/monovm/whois/transport/whois_socket.rb', line 41 def supports?(endpoint) endpoint.socket? end |