7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/rdf_objects/http_client.rb', line 7
def self.fetch(uri)
@@proxies.each do | key, proxy |
if uri.match(key)
uri = proxy.proxy_uri(uri, ['json', 'ntriples','rdf'])
end
end
u = URI.parse(uri)
request = Net::HTTP::Get.new(u.request_uri)
request['accept'] = nil
request['accept'] = ['application/rdf+xml']
response = Net::HTTP.start(u.host, u.port) do | http |
http.request(request)
end
if response.code == "200"
return {:uri=>u.to_s, :content=>response.body}
elsif response.code =~ /^30[0-9]$/
new_uri = URI.parse(response.['location'])
unless new_uri.host
new_uri = u+new_uri
end
return fetch(new_uri.to_s)
else
raise response.message
end
end
|