From 972ed767998291c6fdbfe2d9d9e7e0c357a62632 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Wed, 13 Mar 2013 12:42:54 -0500 Subject: [PATCH] add fake HTTP HEAD checking for google code URLs this allows google code urls to pass link checking. refs #131 --- lib/cask/fetcher.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/cask/fetcher.rb b/lib/cask/fetcher.rb index 11ae67f3d..4891cf2b5 100644 --- a/lib/cask/fetcher.rb +++ b/lib/cask/fetcher.rb @@ -1,5 +1,21 @@ +require 'open3' + class Cask::Fetcher + TIMEOUT = 10 + def self.head(url) - `curl --max-time 5 --silent --location --head '#{url}'` + if url.to_s =~ /googlecode/ + googlecode_fake_head(url) + else + `curl --max-time #{TIMEOUT} --silent --location --head '#{url}'` + end + end + + # google code does not properly respond to HTTP HEAD requests, like a jerk + # this fakes a HEAD by doing a GET, taking the first 20 lines, then running away + def self.googlecode_fake_head(url) + command = "curl --max-time #{TIMEOUT} --verbose --location '#{url}' | head -n 20 > /dev/null" + stderr = Open3.popen3(command) { |_, _, err, _| err.read } + stderr.split("\n").grep(/^< /).map { |line| line.sub(/^< /, '') }.join("\n") end end