lib/miteru/kit.rb in miteru-0.14.4 vs lib/miteru/kit.rb in miteru-0.14.5

- old
+ new

@@ -4,19 +4,20 @@ require "securerandom" module Miteru class Kit VALID_EXTENSIONS = Miteru.configuration.valid_extensions + VALID_MIME_TYPES = Miteru.configuration.valid_mime_types attr_reader :url def initialize(url) @url = url end def valid?; - valid_ext? && reachable_and_archive_file? + valid_ext? && reachable_and_valid_mime_type? end def extname return ".tar.gz" if url.end_with?("tar.gz") @@ -71,16 +72,17 @@ def reachable?(response) response.status.success? end - def archive_file?(response) - !response.content_type.mime_type.to_s.start_with? "text/" + def valid_mime_type?(response) + mime_type = response.content_type.mime_type.to_s + VALID_MIME_TYPES.include? mime_type end - def reachable_and_archive_file? + def reachable_and_valid_mime_type? res = HTTPClient.head(url) - reachable?(res) && archive_file?(res) + reachable?(res) && valid_mime_type?(res) rescue StandardError false end end end