class Proxy::Omaha::HttpVerify

Attributes

filename[RW]
http_request[RW]
local_file[RW]

Public Class Methods

new(opts = {}) click to toggle source
# File lib/smart_proxy_omaha/http_verify.rb, line 7
def initialize(opts = {})
  self.http_request = opts.fetch(:http_request)
  self.local_file = opts.fetch(:local_file)
  self.filename = opts.fetch(:filename, File.basename(local_file))
end

Public Instance Methods

content_length() click to toggle source
# File lib/smart_proxy_omaha/http_verify.rb, line 64
def content_length
  length = headers['content-length'] || headers['x-goog-stored-content-length']
  length.first.to_i if length
end
file_size_valid?() click to toggle source
# File lib/smart_proxy_omaha/http_verify.rb, line 20
def file_size_valid?
  unless remote_size
    logger.error "#{filename}: Cannot determine remote file size."
    return false
  end
  unless local_size == remote_size
    logger.debug "#{filename}: File sizes do not match. Remote: #{remote_size}, Local: #{local_size}"
    return false
  end
  true
end
headers() click to toggle source
# File lib/smart_proxy_omaha/http_verify.rb, line 69
def headers
  @headers ||= http_request.to_hash
end
local_md5() click to toggle source
# File lib/smart_proxy_omaha/http_verify.rb, line 56
def local_md5
  @local_md5 ||= Digest::MD5.file(local_file).base64digest
end
local_size() click to toggle source
# File lib/smart_proxy_omaha/http_verify.rb, line 32
def local_size
  File.size(local_file)
end
md5_hash_valid?() click to toggle source
# File lib/smart_proxy_omaha/http_verify.rb, line 40
def md5_hash_valid?
  unless local_md5 == remote_md5
    logger.debug "#{filename}: MD5 checksums do not match. Remote: #{remote_md5}, Local: #{local_md5}"
    return false
  end
  true
end
remote_hashes() click to toggle source
# File lib/smart_proxy_omaha/http_verify.rb, line 48
def remote_hashes
  headers['x-goog-hash'].inject({}) do |hsh, header|
    key, value = header.split('=', 2)
    hsh[key] = value
    hsh
  end
end
remote_md5() click to toggle source
# File lib/smart_proxy_omaha/http_verify.rb, line 60
def remote_md5
  remote_hashes['md5']
end
remote_size() click to toggle source
# File lib/smart_proxy_omaha/http_verify.rb, line 36
def remote_size
  @remote_size ||= content_length
end
valid?() click to toggle source
# File lib/smart_proxy_omaha/http_verify.rb, line 13
def valid?
  logger.debug "#{filename}: Verifying if file is valid."
  return false unless file_size_valid?
  return false if headers['x-goog-hash'] && !md5_hash_valid?
  true
end