module FaviconParty::HTTPClient
For now, wrap command-line curl rather than using net/http or open-uri because of easier/more reliable SSL handling
Constants
- TIMEOUT
Public Instance Methods
bin_get(url)
click to toggle source
Get binary data from url and ignore errors
# File lib/favicon_party/http_client.rb, line 34 def bin_get(url) `#{curl_get_cmd(url)} 2>/dev/null` end
build_curl_cmd(url, flags = "")
click to toggle source
# File lib/favicon_party/http_client.rb, line 43 def build_curl_cmd(url, flags = "") "curl #{curl_shared_flags} #{flags} '#{prefix_url(url, :downcase => false)}'" end
curl_get_cmd(url)
click to toggle source
# File lib/favicon_party/http_client.rb, line 47 def curl_get_cmd(url) build_curl_cmd url, "--compressed --fail --show-error" end
curl_head_cmd(url)
click to toggle source
# File lib/favicon_party/http_client.rb, line 51 def curl_head_cmd(url) build_curl_cmd url, "-I -1" end
get(url)
click to toggle source
Encodes output as utf8 - Not for binary http responses
# File lib/favicon_party/http_client.rb, line 16 def get(url) stdin, stdout, stderr, t = Open3.popen3(curl_get_cmd(url)) output = encode_utf8(stdout.read).strip error = encode_utf8(stderr.read).strip if !error.nil? && !error.empty? if error.include? "SSL" raise FaviconParty::Curl::SSLError.new(error) elsif error.include? "Couldn't resolve host" raise FaviconParty::Curl::DNSError.new(error) else raise FaviconParty::CurlError.new(error) end end output end
head(url)
click to toggle source
# File lib/favicon_party/http_client.rb, line 38 def head(url) response_headers = `#{curl_head_cmd(url)}` encode_utf8 response_headers end