diff --git a/lib/em-webfinger.rb b/lib/em-webfinger.rb index 102760156..f6a3539f7 100644 --- a/lib/em-webfinger.rb +++ b/lib/em-webfinger.rb @@ -6,7 +6,7 @@ class EMWebfinger def initialize(account) @account = account.strip.gsub('acct:','').to_s @callbacks = [] - @ssl = false + @ssl = true # Raise an error if identifier has a port number raise "Identifier is invalid" if(@account.strip.match(/\:\d+$/)) # Raise an error if identifier is not a valid email (generous regexp) @@ -44,8 +44,12 @@ class EMWebfinger } http.errback { - - process_callbacks "there was an error getting the xrd from account#{@account}" } + if @ssl + @ssl = false + get_xrd + else + process_callbacks "there was an error getting the xrd from account#{@account}" + end } end diff --git a/spec/lib/em-webfinger_spec.rb b/spec/lib/em-webfinger_spec.rb index eb88684a4..5441d3f91 100644 --- a/spec/lib/em-webfinger_spec.rb +++ b/spec/lib/em-webfinger_spec.rb @@ -156,7 +156,6 @@ describe EMWebfinger do } end - it 'must try https first' do single_request = FakeHttpRequest.new(:success) single_request.callbacks = [diaspora_xrd] @@ -172,6 +171,23 @@ describe EMWebfinger do } } end + + it 'should retry with http if https fails with an http error code' do + bad_request = FakeHttpRequest.new(:failure) + + good_request.callbacks = [diaspora_xrd, diaspora_finger, hcard_xml] + + EventMachine::HttpRequest.should_receive(:new).with("https://tom.joindiaspora.com/.well-known/host-meta").and_return(bad_request) + EventMachine::HttpRequest.should_receive(:new).exactly(3).and_return(good_request) + + f = EMWebfinger.new("tom@tom.joindiaspora.com") + + EM.run { + f.on_person{ |p| + EM.stop + } + } + end end end end