@@ -3,9 +3,11 @@ package main
33import (
44 "encoding/json"
55 "flag"
6+ "fmt"
67 "io"
78 "log"
89 "net"
10+ "net/http"
911 "net/url"
1012 "os"
1113 "path/filepath"
@@ -158,7 +160,8 @@ func (c *config) apiClient(flags *api.Flags, out io.Writer) api.Client {
158160 })
159161}
160162
161- // readConfig reads the config file from the given path.
163+ // readConfig reads the config from the standard config file, the (deprecated) user-specified config file,
164+ // the environment variables, and the (deprecated) command-line flags.
162165func readConfig () (* config , error ) {
163166 cfgFile := * configPath
164167 userSpecified := * configPath != ""
@@ -271,12 +274,20 @@ func readConfig() (*config, error) {
271274 return nil , errors .Newf ("invalid proxy configuration: %w" , err )
272275 }
273276 if ! isValidUDS {
274- return nil , errors .Newf ("invalid proxy socket: %s" , path )
277+ return nil , errors .Newf ("Invalid proxy socket: %s" , path )
275278 }
276279 cfg .proxyPath = path
277280 } else {
278281 return nil , errors .Newf ("invalid proxy endpoint: %s" , proxyStr )
279282 }
283+ } else {
284+ // no SRC_PROXY; check for the standard proxy env variables HTTP_PROXY, HTTPS_PROXY, and NO_PROXY
285+ if u , err := http .ProxyFromEnvironment (& http.Request {URL : cfg .endpointURL }); err != nil {
286+ // when there's an error, the value for the env variable is not a legit URL
287+ return nil , fmt .Errorf ("Invalid HTTP_PROXY or HTTPS_PROXY value: %w" , err )
288+ } else {
289+ cfg .proxyURL = u
290+ }
280291 }
281292
282293 cfg .additionalHeaders = parseAdditionalHeaders ()
0 commit comments