From 29d713ee0c8c25fcf74c4292ff13fe1fa4d0d827 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Wed, 19 Jul 2017 14:17:39 +0200 Subject: [PATCH 1/2] Fixed issue #6 - Domains without an AAA record / that are not reacable fail further lookup tries. --- lib/autodiscover/pox_request.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/autodiscover/pox_request.rb b/lib/autodiscover/pox_request.rb index fc661b3..9ab02f4 100644 --- a/lib/autodiscover/pox_request.rb +++ b/lib/autodiscover/pox_request.rb @@ -19,7 +19,7 @@ def autodiscover begin response = client.http.post(url, request_body, {'Content-Type' => 'text/xml; charset=utf-8'}) return PoxResponse.new(response.body) if good_response?(response) - rescue Errno::ENETUNREACH, Errno::ECONNREFUSED, HTTPClient::ConnectTimeoutError + rescue SocketError, Errno::EHOSTUNREACH, Errno::ENETUNREACH, Errno::ECONNREFUSED, HTTPClient::ConnectTimeoutError next rescue OpenSSL::SSL::SSLError options[:ignore_ssl_errors] ? next : raise From ee9b53dfa797ce6d4f970b82beea7fbdd2df56bb Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Nov 2017 11:52:04 +0100 Subject: [PATCH 2/2] Fixed bug: SocketError in redirected_http_url fails (to) hard. --- lib/autodiscover/pox_request.rb | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/autodiscover/pox_request.rb b/lib/autodiscover/pox_request.rb index 9ab02f4..7437d1c 100644 --- a/lib/autodiscover/pox_request.rb +++ b/lib/autodiscover/pox_request.rb @@ -16,21 +16,13 @@ def initialize(client, **options) # @return [Autodiscover::PoxResponse, nil] def autodiscover available_urls.each do |url| - begin - response = client.http.post(url, request_body, {'Content-Type' => 'text/xml; charset=utf-8'}) - return PoxResponse.new(response.body) if good_response?(response) - rescue SocketError, Errno::EHOSTUNREACH, Errno::ENETUNREACH, Errno::ECONNREFUSED, HTTPClient::ConnectTimeoutError - next - rescue OpenSSL::SSL::SSLError - options[:ignore_ssl_errors] ? next : raise - end + response = client.http.post(url, request_body, {'Content-Type' => 'text/xml; charset=utf-8'}) + return PoxResponse.new(response.body) if good_response?(response) end end - private - def good_response?(response) response.status == 200 end @@ -39,10 +31,14 @@ def available_urls(&block) return to_enum(__method__) unless block_given? formatted_https_urls.each {|url| logger.debug "Yielding HTTPS Url #{url}" - yield url + handle_allowed_errors do + yield url + end } - logger.debug "Yielding HTTP Redirected Url #{redirected_http_url}" - yield redirected_http_url + handle_allowed_errors do + logger.debug "Yielding HTTP Redirected Url #{redirected_http_url}" + yield redirected_http_url + end end def formatted_https_urls @@ -71,5 +67,11 @@ def request_body end.to_xml end + def handle_allowed_errors + yield + rescue SocketError, Errno::EHOSTUNREACH, Errno::ENETUNREACH, Errno::ECONNREFUSED, HTTPClient::ConnectTimeoutError + rescue OpenSSL::SSL::SSLError + raise if !options[:ignore_ssl_errors] + end end end