C0 code coverage information
Generated on Fri Jul 11 15:55:32 -0700 2008 with rcov 0.7.0
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
1 require "cgi"
2 require "openid/yadis/xri"
3 require "openid/yadis/xrds"
4 require "openid/fetchers"
5
6 module OpenID
7
8 module Yadis
9
10 module XRI
11
12 class XRIHTTPError < StandardError; end
13
14 class ProxyResolver
15
16 DEFAULT_PROXY = 'http://proxy.xri.net/'
17
18 def initialize(proxy_url=nil)
19 if proxy_url
20 @proxy_url = proxy_url
21 else
22 @proxy_url = DEFAULT_PROXY
23 end
24
25 @proxy_url += '/' unless @proxy_url.match('/$')
26 end
27
28 def query_url(xri, service_type=nil)
29 # URI normal form has a leading xri://, but we need to strip
30 # that off again for the QXRI. This is under discussion for
31 # XRI Resolution WD 11.
32 qxri = XRI.to_uri_normal(xri)[6..-1]
33 hxri = @proxy_url + qxri
34 args = {'_xrd_r' => 'application/xrds+xml'}
35 if service_type
36 args['_xrd_t'] = service_type
37 else
38 # don't perform service endpoint selection
39 args['_xrd_r'] += ';sep=false'
40 end
41
42 return XRI.append_args(hxri, args)
43 end
44
45 def query(xri, service_types)
46 # these can be query args or http headers, needn't be both.
47 # headers = {'Accept' => 'application/xrds+xml;sep=true'}
48 canonicalID = nil
49
50 services = service_types.collect { |service_type|
51 url = self.query_url(xri, service_type)
52 begin
53 response = OpenID.fetch(url)
54 rescue
55 raise XRIHTTPError, ["Could not fetch #{xri}", $!]
56 end
57 raise XRIHTTPError, "Could not fetch #{xri}" if response.nil?
58
59 xrds = Yadis::parseXRDS(response.body)
60 canonicalID = Yadis::get_canonical_id(xri, xrds)
61
62 Yadis::services(xrds) unless xrds.nil?
63 }
64 # TODO:
65 # * If we do get hits for multiple service_types, we're almost
66 # certainly going to have duplicated service entries and
67 # broken priority ordering.
68 services = services.inject([]) { |flatter, some_services|
69 flatter += some_services unless some_services.nil?
70 }
71
72 return canonicalID, services
73 end
74 end
75
76 def self.urlencode(args)
77 a = []
78 args.each do |key, val|
79 a << (CGI::escape(key) + "=" + CGI::escape(val))
80 end
81 a.join("&")
82 end
83
84 def self.append_args(url, args)
85 return url if args.length == 0
86
87 # rstrip question marks
88 rstripped = url.dup
89 while rstripped[-1].chr == '?'
90 rstripped = rstripped[0...rstripped.length-1]
91 end
92
93 if rstripped.index('?')
94 sep = '&'
95 else
96 sep = '?'
97 end
98
99 return url + sep + XRI.urlencode(args)
100 end
101
102 end
103
104 end
105
106 end
Generated using the rcov code coverage analysis tool for Ruby version 0.7.0.