4
5
6
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/web_utils.rb', line 4
def self.fspfetch(url:, headers: ACCEPT_STAR_HEADER, method: :get, meta: HarvesterTools::MetadataObject.new)
warn 'In fetch routine now. '
begin
warn "executing call over the Web to #{url}"
response = RestClient::Request.execute({
method: method,
url: url.to_s,
headers:
})
meta.all_uris |= [response.request.url] warn "starting URL #{url}"
warn "final URL #{response.request.url}"
warn "Response code #{response.code}"
if response.code == 203
meta.add_warning(["002", url, ])
meta. << "WARN: Response is non-authoritative (HTTP response code: #{response.code}). Headers may have been manipulated encountered when trying to resolve #{url}\n"
end
response
rescue RestClient::ExceptionWithResponse => e
warn "EXCEPTION WITH RESPONSE! #{e.response.code} with response #{e.response}\nfailed response headers: #{e.response.}"
meta.add_warning(["003", url, ])
meta. << "WARN: HTTP error #{e} encountered when trying to resolve #{url}\n"
if (e.response.code == 500 or e.response.code == 404)
return false
else
e.response
end
rescue RestClient::Exception => e
warn "EXCEPTION WITH NO RESPONSE! #{e}"
meta.add_warning(["003", url, ])
meta. << "WARN: HTTP error #{e} encountered when trying to resolve #{url}\n"
false
rescue Exception => e
warn "EXCEPTION UNKNOWN! #{e}"
meta.add_warning(["003", url, ])
meta. << "WARN: HTTP error #{e} encountered when trying to resolve #{url}\n"
false
end
end
|