Skip to content

Commit

Permalink
Fetch the XRDS one time for all service types
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Mell authored and chowells79 committed Jul 20, 2010
1 parent 8f49a81 commit 8e979da
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
3 changes: 1 addition & 2 deletions lib/openid/consumer/discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,7 @@ def self.discover_xri(iname)
iname = self.normalize_xri(iname)

begin
canonical_id, services = Yadis::XRI::ProxyResolver.new().query(
iname, OpenIDServiceEndpoint::OPENID_TYPE_URIS)
canonical_id, services = Yadis::XRI::ProxyResolver.new().query( iname )

if canonical_id.nil?
raise Yadis::XRDSError.new(sprintf('No CanonicalID found for XRI %s', iname))
Expand Down
15 changes: 4 additions & 11 deletions lib/openid/yadis/xrires.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,27 @@ def query_url(xri, service_type=nil)
return XRI.append_args(hxri, args)
end

def query(xri, service_types)
def query(xri)
# these can be query args or http headers, needn't be both.
# headers = {'Accept' => 'application/xrds+xml;sep=true'}
canonicalID = nil

services = service_types.collect { |service_type|
url = self.query_url(xri, service_type)
url = self.query_url(xri)
begin
response = OpenID.fetch(url)
rescue
raise XRIHTTPError, ["Could not fetch #{xri}", $!]
raise XRIHTTPError, "Could not fetch #{xri}, #{$!}"
end
raise XRIHTTPError, "Could not fetch #{xri}" if response.nil?

xrds = Yadis::parseXRDS(response.body)
canonicalID = Yadis::get_canonical_id(xri, xrds)

Yadis::services(xrds) unless xrds.nil?
}
return canonicalID, Yadis::services(xrds)
# TODO:
# * If we do get hits for multiple service_types, we're almost
# certainly going to have duplicated service entries and
# broken priority ordering.
services = services.inject([]) { |flatter, some_services|
flatter += some_services unless some_services.nil?
}

return canonicalID, services
end
end

Expand Down

0 comments on commit 8e979da

Please sign in to comment.