From 0902b8ba3af430226944d7b5093b401b05c46972 Mon Sep 17 00:00:00 2001 From: Ruben Jenster Date: Fri, 31 Jul 2020 13:46:15 +0200 Subject: [PATCH] Add --no-proxy flag to disable http proxy. --- goget.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/goget.go b/goget.go index 7a832b4..2fcc110 100644 --- a/goget.go +++ b/goget.go @@ -23,6 +23,7 @@ type client struct { ReadTimeout time.Duration Retries int RetryWait time.Duration + NoProxy bool } func main() { @@ -38,6 +39,7 @@ func main() { flag.DurationVar(&c.ReadTimeout, "read-timeout", 10*time.Second, "TCP connections that that are longer idle will be aborted") flag.BoolVar(&c.Insecure, "insecure", false, "Disable TLS certificate verification.") flag.BoolVar(&showVersion, "version", false, "Show version and exit.") + flag.BoolVar(&c.NoProxy, "no-proxy", false, "Ignore *_proxy environment variables.") flag.StringVar(&filename, "filename", "", "Filename / path where to write downloaded file to. Defaults to filename of the URL.") flag.Parse() @@ -95,6 +97,12 @@ func (c *client) DownloadFile(filename string, url string) (err error) { }, } + if c.NoProxy { + tr.Proxy = nil + } else { + tr.Proxy = http.ProxyFromEnvironment + } + client := &http.Client{Transport: tr} // Get the data