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
49
50
51
52
53
|
# File 'lib/nitlink/response_normalizer.rb', line 6
def metadata(response)
response_class = response.class.name
uri, status, (link, content_location) = case response_class
when 'Curl::Easy'
[response.url.chomp('?'), response.response_code, ( response.)]
when 'Excon::Response'
scheme = response.port == 443 ? 'https' : 'http'
uri = URI::HTTP.new(scheme, nil, response.host, nil, nil, response.path, nil, nil, nil)
[uri, response.status, (response.)]
when 'Faraday::Response'
response = response.to_hash
[response[:url], response[:status], (response[:response_headers])]
when 'HTTP::Message'
[response..request_uri, response.status, (Hash[response..all])]
when 'HTTP::Response'
[response.uri, response.status, (response..to_h)]
when 'HTTParty::Response'
[response.request.uri, response.code, (response.response.to_hash)]
when 'Patron::Response'
[response.url, response.status, (response.)]
when 'RestClient::Response'
[response.request.url, response.code, (response.net_http_res.to_hash)]
when 'Tempfile', 'StringIO'
[response.base_uri, response.status[0], (response.meta)]
when 'Typhoeus::Response'
[response.request.base_url, response.code, (response.)]
when 'Unirest::HttpResponse'
warn "Unirest support is deprecated and will be removed in Nitlink 2.0"
return metadata(response.raw_body)
when 'Hash'
response = Nitlink::HashWithIndifferentAccess.new(response)
response[:headers] = (response[:headers]) if String === response[:headers]
[response[:request_uri], response[:status], (response[:headers])]
else
if defined?(Net::HTTPResponse) && Net::HTTPResponse === response
[response.uri, response.code, (response.to_hash)]
else
raise unknown_type(response)
end
end
[URI.parse(uri.to_s), (status ? Integer(status) : status), link, content_location]
end
|