foreman/lib/foreman/http_proxy.rb @ b5eca9b3
7f8fd14d | Sebastian Gräßl | module Foreman
|
|
module HTTPProxy
|
|||
def http_proxy
|
|||
Setting[:http_proxy]
|
|||
end
|
|||
def http_proxy_except_list
|
|||
Setting[:http_proxy_except_list]
|
|||
end
|
|||
e59a1da9 | Sebastian Gräßl | # Answers if this request should be proxied
|
|
7f8fd14d | Sebastian Gräßl | def proxy_http_request?(current_proxy, request_host, schema)
|
|
e59a1da9 | Sebastian Gräßl | !http_proxy.nil? &&
|
|
current_proxy.nil? &&
|
|||
!request_host.nil? &&
|
|||
7f8fd14d | Sebastian Gräßl | http_request?(schema) &&
|
|
e59a1da9 | Sebastian Gräßl | http_proxy_host?(request_host) &&
|
|
!local_request?(request_host)
|
|||
7f8fd14d | Sebastian Gräßl | end
|
|
def http_proxied_rescue(&block)
|
|||
yield
|
|||
rescue => e
|
|||
df1215f9 | Lukas Zapletal | raise e, _("Proxied request failed with: %s\n%s") % [e, e&.backtrace&.join("\n")]
|
|
7f8fd14d | Sebastian Gräßl | end
|
|
private
|
|||
e59a1da9 | Sebastian Gräßl | def local_request?(request_host)
|
|
request_host.starts_with?('127.') ||
|
|||
request_host == 'localhost' ||
|
|||
request_host == '::1' ||
|
|||
request_host == SETTINGS[:fqdn]
|
|||
end
|
|||
7f8fd14d | Sebastian Gräßl | def http_request?(schema)
|
|
['http', 'https'].include?(schema)
|
|||
end
|
|||
def http_proxy_host?(request_host)
|
|||
!http_host_excepted?(request_host) &&
|
|||
!http_host_excepted_by_wildcard?(request_host)
|
|||
end
|
|||
a082d9ca | Michael Moll | def foreman_logger
|
|
7f8fd14d | Sebastian Gräßl | Foreman::Logging.logger('app')
|
|
end
|
|||
def log_proxied_request(current_proxy, requested_host)
|
|||
a082d9ca | Michael Moll | foreman_logger.info "Proxying request to #{requested_host} via #{current_proxy}"
|
|
7f8fd14d | Sebastian Gräßl | end
|
|
def http_host_excepted_by_wildcard?(host)
|
|||
return false if http_proxy_except_list.empty?
|
|||
host =~ Setting.convert_array_to_regexp(http_proxy_except_list)
|
|||
end
|
|||
def http_host_excepted?(host)
|
|||
http_proxy_except_list.include? host
|
|||
end
|
|||
end
|
|||
end
|
|||
b5eca9b3 | Michael Moll | require_dependency File.expand_path('http_proxy/excon_connection_extension', __dir__)
|
|
require_dependency File.expand_path('http_proxy/net_http_extension', __dir__)
|
|||
require_dependency File.expand_path('http_proxy/rest_client_extension', __dir__)
|