Add --no-proxy flag to disable http proxy.

This commit is contained in:
2020-07-31 13:46:15 +02:00
parent c1d5863162
commit 0902b8ba3a

View File

@ -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