diff --git a/lib/file_helper.rb b/lib/file_helper.rb index 6de82ad7f29..10fa7bb0006 100644 --- a/lib/file_helper.rb +++ b/lib/file_helper.rb @@ -33,8 +33,6 @@ class FileHelper url = "https:" + url if url.start_with?("//") raise Discourse::InvalidParameters.new(:url) unless url =~ /^https?:\/\// - uri = - dest = FinalDestination.new( url, max_redirects: follow_redirect ? 5 : 1, diff --git a/lib/final_destination.rb b/lib/final_destination.rb index dae0cea24bb..357700ee44b 100644 --- a/lib/final_destination.rb +++ b/lib/final_destination.rb @@ -93,6 +93,7 @@ class FinalDestination if @limit < 0 @status = :too_many_redirects + log(:warn, "FinalDestination could not resolve URL (too many redirects): #{@uri}") return nil end @@ -103,7 +104,11 @@ class FinalDestination end end - return nil unless validate_uri + unless validate_uri + log(:warn, "FinalDestination could not resolve URL (invalid URI): #{@uri}") + return nil + end + headers = request_headers response = Excon.public_send(@http_verb, @uri.to_s, @@ -175,8 +180,10 @@ class FinalDestination @status = :failure @status_code = response.status + log(:warn, "FinalDestination could not resolve URL (status #{response.status}): #{@uri}") nil rescue Excon::Errors::Timeout + log(:warn, "FinalDestination could not resolve URL (timeout): #{@uri}") nil end @@ -246,6 +253,13 @@ class FinalDestination SiteSetting.blacklist_ip_blocks.split('|').map { |r| IPAddr.new(r) rescue nil }.compact end + def log(log_level, message) + Rails.logger.public_send( + log_level, + "#{RailsMultisite::ConnectionManagement.current_db}: #{message}" + ) + end + def self.standard_private_ranges @private_ranges ||= [ IPAddr.new('127.0.0.1'),