Sha256: f1f6c894cfb0f7a581923e41c48e9af523cb7ace48a8c7ec7c212ef0a77870b0
Contents?: true
Size: 1.29 KB
Versions: 14
Compression:
Stored size: 1.29 KB
Contents
require 'tempfile' module Percy module Capybara module HttpFetcher class Response < Struct.new(:body, :content_type); end def self.fetch(url) tempfile = Tempfile.new('percy-capybara-fetch') temppath = tempfile.path # Close and delete the tempfile, we just wanted the name. Also, we use the existence of the # file as a signal below. tempfile.close tempfile.unlink # Use curl as a magical subprocess weapon which escapes this Ruby sandbox and is not # influenced by any HTTP middleware/restrictions. This helps us avoid causing lots of # problems for people using gems like VCR/WebMock. We also disable certificate checking # because, as odd as that is, it's the default state for Selenium Firefox and others. output = `curl --insecure -v -o #{temppath} "#{url}" 2>&1` content_type = output.match(/< Content-Type:(.*)/i) content_type = content_type[1].strip if content_type if File.exist?(temppath) response = Percy::Capybara::HttpFetcher::Response.new(File.read(temppath), content_type) # We've broken the tempfile so it won't get deleted when garbage collected. Delete! File.delete(temppath) response end end end end end
Version data entries
14 entries across 14 versions & 1 rubygems