@@ -45,7 +45,7 @@ def __init__(self, request_uri):
4545
4646 def usedYadisLocation (self ):
4747 """Was the Yadis protocol's indirection used?"""
48- return self .normalized_uri = = self .xrds_uri
48+ return self .normalized_uri ! = self .xrds_uri
4949
5050 def isXRDS (self ):
5151 """Is the response text supposed to be an XRDS document?"""
@@ -79,11 +79,42 @@ def discover(uri):
7979 # or if we already have it
8080 result .content_type = resp .headers .get ('content-type' )
8181
82+ result .xrds_uri = whereIsYadis (resp )
83+
84+ if result .xrds_uri and result .usedYadisLocation ():
85+ resp = fetchers .fetch (result .xrds_uri )
86+ if resp .status != 200 :
87+ exc = DiscoveryFailure (
88+ 'HTTP Response status from Yadis host is not 200. '
89+ 'Got status %r' % (resp .status ,), resp )
90+ exc .identity_url = result .normalized_uri
91+ raise exc
92+ result .content_type = resp .headers .get ('content-type' )
93+
94+ result .response_text = resp .body
95+ return result
96+
97+
98+
99+ def whereIsYadis (resp ):
100+ """Given a HTTPResponse, return the location of the Yadis document.
101+
102+ May be the URL just retrieved, another URL, or None, if I can't
103+ find any.
104+
105+ [non-blocking]
106+
107+ @returns: str or None
108+ """
109+ # Attempt to find out where to go to discover the document
110+ # or if we already have it
111+ content_type = resp .headers .get ('content-type' )
112+
82113 # According to the spec, the content-type header must be an exact
83114 # match, or else we have to look for an indirection.
84- if (result . content_type and
85- result . content_type .split (';' , 1 )[0 ].lower () == YADIS_CONTENT_TYPE ):
86- result . xrds_uri = result . normalized_uri
115+ if (content_type and
116+ content_type .split (';' , 1 )[0 ].lower () == YADIS_CONTENT_TYPE ):
117+ return resp . final_url
87118 else :
88119 # Try the header
89120 yadis_loc = resp .headers .get (YADIS_HEADER_NAME .lower ())
@@ -99,19 +130,5 @@ def discover(uri):
99130 except MetaNotFound :
100131 pass
101132
102- # At this point, we have not found a YADIS Location URL. We
103- # will return the content that we scanned so that the caller
104- # can try to treat it as an XRDS if it wishes.
105- if yadis_loc :
106- result .xrds_uri = yadis_loc
107- resp = fetchers .fetch (yadis_loc )
108- if resp .status != 200 :
109- exc = DiscoveryFailure (
110- 'HTTP Response status from Yadis host is not 200. '
111- 'Got status %r' % (resp .status ,), resp )
112- exc .identity_url = result .normalized_uri
113- raise exc
114- result .content_type = resp .headers .get ('content-type' )
133+ return yadis_loc
115134
116- result .response_text = resp .body
117- return result
0 commit comments