Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/java_buildpack/util/cache/download_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,11 @@ def proxy(uri)
URI.parse(ENV['http_proxy'] || ENV['HTTP_PROXY'] || '')
end

@logger.debug { "Proxy: #{proxy_uri.host}, #{proxy_uri.port}, #{proxy_uri.user}, #{proxy_uri.password}" }
Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
proxy_user = proxy_uri.user ? URI.decode_www_form_component(proxy_uri.user) : nil
proxy_pass = proxy_uri.password ? URI.decode_www_form_component(proxy_uri.password) : nil

@logger.debug { "Proxy: #{proxy_uri.host}, #{proxy_uri.port}, #{proxy_user}, #{proxy_pass}" }
Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port, proxy_user, proxy_pass)
end

def redirect?(response)
Expand Down
32 changes: 32 additions & 0 deletions spec/java_buildpack/util/cache/download_cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,22 @@

end

context do

let(:environment) { { 'HTTP_PROXY' => 'http://user%21:pass%40@proxy:9000', 'http_proxy' => nil } }

it 'decodes user/pass from HTTP_PROXY if encoded' do
stub_request(:get, uri)
.to_return(status: 200, body: 'foo-cached', headers: { Etag: 'foo-etag',
'Last-Modified' => 'foo-last-modified' })

allow(Net::HTTP).to receive(:Proxy).with('proxy', 9000, /user!/, /pass@/).and_call_original

download_cache.get(uri) {}
end

end

context do

let(:environment) { { 'https_proxy' => 'http://proxy:9000', 'HTTPS_PROXY' => nil } }
Expand Down Expand Up @@ -257,6 +273,22 @@

end

context do

let(:environment) { { 'HTTPS_PROXY' => 'http://user%21:pass%40@proxy:9000', 'https_proxy' => nil } }

it 'decodes user/pass from HTTPS_PROXY if encoded' do
stub_request(:get, uri_secure)
.to_return(status: 200, body: 'foo-cached', headers: { Etag: 'foo-etag',
'Last-Modified' => 'foo-last-modified' })

allow(Net::HTTP).to receive(:Proxy).with('proxy', 9000, /user!/, /pass@/).and_call_original

download_cache.get(uri_secure) {}
end

end

context do
let(:environment) { { 'NO_PROXY' => '127.0.0.1,localhost,foo-uri,.foo-uri', 'HTTPS_PROXY' => 'http://proxy:9000' } }

Expand Down