def head(uri_or_str, readtimeout=10, opentimeout=5, max_redir=@bot.config["http.max_redir"])
if uri_or_str.class <= URI
uri = uri_or_str
else
uri = URI.parse(uri_or_str.to_s)
end
proxy = get_proxy(uri)
proxy.open_timeout = opentimeout
proxy.read_timeout = readtimeout
begin
proxy.start() {|http|
yield uri.request_uri() if block_given?
resp = http.head(uri.request_uri(), @headers)
case resp
when Net::HTTPSuccess
return resp
when Net::HTTPRedirection
debug "Redirecting #{uri} to #{resp['location']}"
yield resp['location'] if block_given?
if max_redir > 0
return head( URI.parse(resp['location']), readtimeout, opentimeout, max_redir-1)
else
warning "Max redirection reached, not going to #{resp['location']}"
end
else
debug "HttpUtil.head return code #{resp.code}"
end
return nil
}
rescue StandardError, Timeout::Error => e
error "HttpUtil.head exception: #{e.inspect}, while trying to get #{uri}"
debug e.backtrace.join("\n")
end
return nil
end