lib/nanoc/checking/checks/external_links.rb in nanoc-4.11.2 vs lib/nanoc/checking/checks/external_links.rb in nanoc-4.11.3
- old
+ new
@@ -75,10 +75,14 @@
end
location = extract_location(res, url)
return Result.new(href, 'redirection without a target location') if location.nil?
+ if /^30[18]$/.match?(res.code)
+ return Result.new(href, "link have moved permanently to '#{location}'")
+ end
+
url = URI.parse(location)
elsif res.code == '200'
return nil
else
return Result.new(href, res.code)
@@ -123,9 +127,10 @@
path
end
def request_url_once(url)
req = Net::HTTP::Get.new(path_for_url(url))
+ req['User-Agent'] = "Mozilla/5.0 Nanoc/#{Nanoc::VERSION} (link rot checker)"
http = Net::HTTP.new(url.host, url.port)
if url.instance_of? URI::HTTPS
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end