diff --git a/lib/foreman/http_proxy/rest_client_extension.rb b/lib/foreman/http_proxy/rest_client_extension.rb index feba4708570..7048d03f56d 100644 --- a/lib/foreman/http_proxy/rest_client_extension.rb +++ b/lib/foreman/http_proxy/rest_client_extension.rb @@ -8,6 +8,23 @@ def proxy_uri end super end + + def net_http_object(hostname, port) + p_uri = proxy_uri + + if p_uri.nil? + # no proxy set + Net::HTTP.new(hostname, port) + elsif !p_uri + # proxy explicitly set to none + Net::HTTP.new(hostname, port, nil, nil, nil, nil) + else + proxy_pass = p_uri.password ? CGI.unescape(p_uri.password) : nil + proxy_user = p_uri.user ? CGI.unescape(p_uri.user) : nil + Net::HTTP.new(hostname, port, + p_uri.hostname, p_uri.port, proxy_user, proxy_pass) + end + end end end end