mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
add more logging to FinalDestination
This commit is contained in:
parent
b3e61ebb38
commit
8c27f28dcb
|
@ -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,
|
||||
|
|
|
@ -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'),
|
||||
|
|
Loading…
Reference in New Issue
Block a user