Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # なぜか timeout error が起こるので wget で代用
- class Gem::RemoteFetcher
- alias open_uri_or_path_orig open_uri_or_path
- def open_uri_or_path(uri, last_modified = nil, head = false, depth = 0)
- raise "block is dead" if block_given?
- # HEADメソッドならオリジナルに任せる
- return open_uri_or_path_orig(uri, last_modified, head, depth) if head
- uri = URI.parse uri unless URI::Generic === uri
- unless ['http', 'https', 'file'].include?(uri.scheme)
- raise ArgumentError, 'uri scheme is invalid'
- end
- # file://プロトコルならオリジナルに任せる
- return open_uri_or_path_orig(uri, last_modified, head, depth) if uri.scheme == 'file'
- response = nil
- require 'tmpdir'
- Dir.mktmpdir do |dir|
- cmd = "wget"
- unless uri.nil? || uri.user.nil? || uri.user.empty? then
- cmd += " --user=#{uri.user}"
- cmd += " --password=#{uri.password}" if uri.password.to_s.size > 0
- end
- fn = File.join("#{dir}", "#{rand}")
- ua = "RubyGems/#{Gem::RubyGemsVersion} #{Gem::Platform.local}"
- ua << " Ruby/#{RUBY_VERSION} (#{RUBY_RELEASE_DATE}"
- ua << " patchlevel #{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL
- ua << ")"
- cmd += " -U '#{ua}'"
- cmd += " -O '#{fn}'"
- cmd += " -q '#{uri}'"
- system(cmd)
- response = File.open(fn, "rb"){ |f| f.read }
- end
- response
- end
- end
Add Comment
Please, Sign In to add comment