Skip to content

Commit e94d950

Browse files
committed
added proxy authentication support
1 parent fd197b2 commit e94d950

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lib/puppet_forge_server/http/http_client.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ def initialize(cache = nil)
3131
cache.extend(PuppetForgeServer::Utils::FilteringInspecter)
3232
@log = PuppetForgeServer::Logger.get
3333
@cache = cache
34+
@uri_options= {
35+
'User-Agent' => "Puppet-Forge-Server/#{PuppetForgeServer::VERSION}",
36+
:allow_redirections => :safe,
37+
}
38+
# OpenURI does not work with http_proxy=http://username:password@proxyserver:port/
39+
# so split the proxy_url and feed it basic authentication.
40+
if ENV.has_key?('http_proxy')
41+
proxy = URI.parse(ENV['http_proxy'])
42+
if proxy.userinfo != nil
43+
@uri_options[:proxy_http_basic_authentication] = [
44+
"#{proxy.scheme}://#{proxy.host}:#{proxy.port}",
45+
proxy.userinfo.split(':')[0],
46+
proxy.userinfo.split(':')[1]
47+
]
48+
end
49+
end
50+
3451
end
3552

3653
def post_file(url, file_hash, options = {})
@@ -69,7 +86,7 @@ def open_uri(url)
6986
contents = @cache.fetch(url) do
7087
tmpfile = ::Timeout.timeout(10) do
7188
PuppetForgeServer::Logger.get.debug "Fetching data for url: #{url} from remote server"
72-
open(url, 'User-Agent' => "Puppet-Forge-Server/#{PuppetForgeServer::VERSION}", :allow_redirections => :safe)
89+
open(url, @uri_options)
7390
end
7491
contents = tmpfile.read
7592
tmpfile.close

0 commit comments

Comments
 (0)