From 9bf7d7b81b9582168bb239230e48d128ad3a7916 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 18 Aug 2013 12:34:36 -0600 Subject: [PATCH] common: use HTTP proxy if available from env [GH-252] --- CHANGELOG.md | 3 +++ common/download.go | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab587526e..5c8b509c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ ## 0.3.3 (unreleased) +IMPROVEMENTS: +* core: All HTTP downloads across Packer now support the standard + proxy environmental variables (`HTTP_PROXY`, `NO_PROXY`, etc.) [GH-252] ## 0.3.2 (August 18, 2013) diff --git a/common/download.go b/common/download.go index a70a1485c..fb34c7965 100644 --- a/common/download.go +++ b/common/download.go @@ -188,7 +188,18 @@ func (*HTTPDownloader) Cancel() { func (d *HTTPDownloader) Download(dst io.Writer, src *url.URL) error { log.Printf("Starting download: %s", src.String()) - resp, err := http.Get(src.String()) + req, err := http.NewRequest("GET", src.String(), nil) + if err != nil { + return err + } + + httpClient := &http.Client{ + Transport: &http.Transport{ + Proxy: http.ProxyFromEnvironment, + }, + } + + resp, err := httpClient.Do(req) if err != nil { return err }