homebrew-cask-versions/lib/hbc/fetcher.rb
Roland Walker 202d6019f8 Move all code under an Hbc:: namespace
* convert existing Cask:: namespace to Hbc::
* move Homebrew-fork code under Hbc::
* move freestanding classes such as Tty and TopologicalHash under Hbc::
* recast HOMEBREW_CASK_ constants as HBC_
* modify our Homebrew Formula for backward compatibility
* devscripts and dev docs
2015-01-02 07:27:03 -05:00

22 lines
759 B
Ruby

require 'open3'
class Hbc::Fetcher
TIMEOUT = 10
def self.head(url)
if url.to_s =~ /googlecode/
googlecode_fake_head(url)
else
Hbc::SystemCommand.run("curl",
:args => ["--max-time", TIMEOUT, "--silent", "--location", "--head", url]).stdout
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