Sha256: 3628030ad94e88708ee74103019d4c1bd9e0a118603e60de22f380a95420f222
Contents?: true
Size: 1.3 KB
Versions: 2
Compression:
Stored size: 1.3 KB
Contents
# frozen_string_literal: true require "net/http" require "openssl" require "base64" module Apullo module Fingerprint class Favicon attr_reader :uri def initialize(url) @uri = URI(url) end def results data = b64_favicon_data return {} unless data hash = Hash.new(data.b) { md5: hash.md5, mmh3: hash.mmh3, sha1: hash.sha1, sha256: hash.sha256, meta: { url: uri.to_s } } end private def b64_favicon_data @b64_favicon_data ||= [].tap do |out| data = get(uri.path) break unless data b64 = Base64.strict_encode64(data) out << b64.chars.each_slice(76).map(&:join).join("\n") + "\n" end.first end def get(path) http = build_http path = path.empty? ? "/" : path request = Net::HTTP::Get.new(path) response = http.request(request) response.body rescue Errno::ECONNREFUSED, Net::HTTPError, OpenSSL::OpenSSLError => _e nil end def build_http if uri.scheme == "http" Net::HTTP.start(uri.host, uri.port) else Net::HTTP.start(uri.host, uri.port, use_ssl: true) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
apullo-0.1.1 | lib/apullo/fingerprints/favicon.rb |
apullo-0.1.0 | lib/apullo/fingerprints/favicon.rb |