diff options
author | azul <azul@riseup.net> | 2017-07-24 08:05:11 +0000 |
---|---|---|
committer | azul <azul@riseup.net> | 2017-07-24 08:05:11 +0000 |
commit | eda9a0829b670975244f39b89b23ac2695493e75 (patch) | |
tree | 6cad7ae458d6bc349a0ba925f82477feb2010fa1 /lib | |
parent | cfa6395c7e5728de02221b94b5f9cfe8a4debf09 (diff) | |
parent | b1738a78ccf5768f92068a27255f9f69be1c3147 (diff) |
Merge branch 'bugfix/name-resolution' into 'master'
fix: #3 handle domains without A-record
Closes #3
See merge request !15
Diffstat (limited to 'lib')
-rw-r--r-- | lib/nickserver/adapters/http.rb | 15 | ||||
-rw-r--r-- | lib/nickserver/nicknym/source.rb | 3 |
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/nickserver/adapters/http.rb b/lib/nickserver/adapters/http.rb index 636aceb..eb77cc6 100644 --- a/lib/nickserver/adapters/http.rb +++ b/lib/nickserver/adapters/http.rb @@ -2,6 +2,19 @@ require 'nickserver/adapters' require 'nickserver/config' require 'http' +# Nickserver::Adapters::Http +# +# Basic http adapter with ssl and minimal error handling. +# Only implemented get requests so far. +# +# Error Handling: +# +# Pass a string as the 'rescue' option. If a ConnectionError occures +# which includes the string passed it will be rescued and the request +# will return nil. This allows handling the error inside the adapter so +# that for the derived CelluloidHttp Adapter the actor does not get +# killed. + module Nickserver::Adapters class Http @@ -9,6 +22,8 @@ module Nickserver::Adapters url = HTTP::URI.parse url.to_s response = get_with_auth url, params: options[:query] return response.code, response.to_s + rescue HTTP::ConnectionError => e + raise unless options[:rescue] && e.to_s.include?(options[:rescue]) end protected diff --git a/lib/nickserver/nicknym/source.rb b/lib/nickserver/nicknym/source.rb index 96945cb..f49547e 100644 --- a/lib/nickserver/nicknym/source.rb +++ b/lib/nickserver/nicknym/source.rb @@ -8,7 +8,8 @@ module Nickserver PORT = 6425 def available_for?(domain) - status, body = adapter.get "https://#{domain}/provider.json" + status, body = adapter.get "https://#{domain}/provider.json", + rescue: 'failed to connect: getaddrinfo' status == 200 && provider_with_mx?(body) end |