Use curl to download list of Apache mirrors

Ruby's OpenURI library is somewhat broken under 1.8 and chokes on
otherwise valid values of http(s)_proxy. Use curl to get the mirror list
instead.

Fixes Homebrew/homebrew#23708.
This commit is contained in:
Jack Nagel 2013-10-30 00:11:46 -05:00
parent d9f327083b
commit a5b2814770

View File

@ -1,4 +1,3 @@
require 'open-uri'
require 'utils/json'
require 'erb'
@ -208,8 +207,26 @@ end
# Detect and download from Apache Mirror
class CurlApacheMirrorDownloadStrategy < CurlDownloadStrategy
def apache_mirrors
rd, wr = IO.pipe
buf = ""
pid = fork do
rd.close
$stdout.reopen(wr)
$stderr.reopen(wr)
curl "#{@url}&asjson=1"
end
wr.close
buf << rd.read until rd.eof?
rd.close
Process.wait(pid)
buf
end
def _fetch
mirrors = Utils::JSON.load(open("#{@url}&asjson=1").read)
mirrors = Utils::JSON.load(apache_mirrors)
url = mirrors.fetch('preferred') + mirrors.fetch('path_info')
ohai "Best Mirror #{url}"