diff --git a/config.ini b/config.ini index 1f9df1eea..b9320949d 100644 --- a/config.ini +++ b/config.ini @@ -4,4 +4,5 @@ regex = usb|acm|com # Regular expression to filter serial port list v = true # show debug logging appName = CreateBridge updateUrl = http://downloads.arduino.cc/ -origins = http://local.arduino.cc:8000 +origins = http://local.arduino.cc:8080 +#httpProxy = http://your.proxy:port # Proxy server for HTTP requests diff --git a/main.go b/main.go index 81ac6d860..d091d519a 100755 --- a/main.go +++ b/main.go @@ -45,12 +45,14 @@ var ( // iniflags var ( - iniConf = flag.NewFlagSet("ini", flag.ContinueOnError) address = iniConf.String("address", "127.0.0.1", "The address where to listen. Defaults to localhost") appName = iniConf.String("appName", "", "") gcType = iniConf.String("gc", "std", "Type of garbage collection. std = Normal garbage collection allowing system to decide (this has been known to cause a stop the world in the middle of a CNC job which can cause lost responses from the CNC controller and thus stalled jobs. use max instead to solve.), off = let memory grow unbounded (you have to send in the gc command manually to garbage collect or you will run out of RAM eventually), max = Force garbage collection on each recv or send on a serial port (this minimizes stop the world events and thus lost serial responses, but increases CPU usage)") hostname = iniConf.String("hostname", "unknown-hostname", "Override the hostname we get from the OS") + httpProxy = iniConf.String("httpProxy", "", "Proxy server for HTTP requests") + httpsProxy = iniConf.String("httpsProxy", "", "Proxy server for HTTPS requests") indexURL = iniConf.String("indexURL", "https://downloads.arduino.cc/packages/package_staging_index.json", "The address from where to download the index json containing the location of upload tools") + iniConf = flag.NewFlagSet("ini", flag.ContinueOnError) logDump = iniConf.String("log", "off", "off = (default)") origins = iniConf.String("origins", "", "Allowed origin list for CORS") regExpFilter = iniConf.String("regex", "usb|acm|com", "Regular expression to filter serial port list") @@ -178,6 +180,32 @@ func main() { debug.SetGCPercent(-1) } + // If the httpProxy setting is set, use its value to override the + // HTTP_PROXY environment variable. Setting this environment + // variable ensures that all HTTP requests using net/http use this + // proxy server. + if *httpProxy != "" { + log.Printf("Setting HTTP_PROXY variable to %v", *httpProxy) + err := os.Setenv("HTTP_PROXY", *httpProxy) + if err != nil { + // The os.Setenv documentation doesn't specify how it can + // fail, so I don't know how to handle this error + // appropriately. + panic(err) + } + } + + if *httpsProxy != "" { + log.Printf("Setting HTTPS_PROXY variable to %v", *httpProxy) + err := os.Setenv("HTTPS_PROXY", *httpProxy) + if err != nil { + // The os.Setenv documentation doesn't specify how it can + // fail, so I don't know how to handle this error + // appropriately. + panic(err) + } + } + // see if they provided a regex filter if len(*regExpFilter) > 0 { log.Printf("You specified a serial port regular expression filter: %v\n", *regExpFilter) @@ -474,7 +502,7 @@ func parseIni(filename string) (args []string, err error) { if key == "name" { continue } - args = append(args, "-"+key, val) + args = append(args, "-"+key+"="+val) } }