From 29763f2b1d10aec7ad9839c86bdffca27aeea090 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 26 Jan 2018 07:51:43 +0100 Subject: [PATCH 1/4] Add configuration setting to set proxy server Signed-off-by: Hanno Braun --- config.ini | 1 + main.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/config.ini b/config.ini index eec98cd7a..2dbc36b07 100644 --- a/config.ini +++ b/config.ini @@ -8,3 +8,4 @@ appName = CreateBridge updateUrl = http://downloads.arduino.cc/ #updateUrl = http://localhost/ origins = http://webide.arduino.cc:8080 +#httpProxy = http://your.proxy:port # Proxy server for HTTP requests diff --git a/main.go b/main.go index 58a3c359b..95a88e6c2 100755 --- a/main.go +++ b/main.go @@ -47,6 +47,7 @@ var ( Tools tools.Tools indexURL = flag.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") requiredToolsAPILevel = "v1" + httpProxy = flag.String("httpProxy", "", "Proxy server for HTTP requests") ) type NullWriter int @@ -124,6 +125,21 @@ func main() { iniflags.Parse() } + // 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) + } + } + // move CORS to config file compatibility, Vagrant version if *origins == "" { log.Println("Patching config.ini for compatibility") From db4513e79e20f403708ed68cc00dc3265544f7ca Mon Sep 17 00:00:00 2001 From: Matteo Suppo Date: Wed, 25 Jul 2018 11:02:01 +0200 Subject: [PATCH 2/4] Add httpsProxy variable --- main.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/main.go b/main.go index 7ad06cd32..ba8616340 100755 --- a/main.go +++ b/main.go @@ -49,6 +49,7 @@ var ( indexURL = flag.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") requiredToolsAPILevel = "v1" httpProxy = flag.String("httpProxy", "", "Proxy server for HTTP requests") + httpsProxy = flag.String("httpsProxy", "", "Proxy server for HTTPS requests") ) type NullWriter int @@ -141,6 +142,17 @@ func main() { } } + 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) + } + } + // move CORS to config file compatibility, Vagrant version if *origins == "" { log.Println("Patching config.ini for compatibility") From 2133d4077de2251f3c6c63be453bc778777b34ed Mon Sep 17 00:00:00 2001 From: Matteo Suppo Date: Thu, 26 Jul 2018 12:43:41 +0200 Subject: [PATCH 3/4] Move proxy flags in iniflags --- main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 03d7ca2a9..3dbced61c 100755 --- a/main.go +++ b/main.go @@ -33,8 +33,6 @@ var ( port string portSSL string requiredToolsAPILevel = "v1" - httpProxy = flag.String("httpProxy", "", "Proxy server for HTTP requests") - httpsProxy = flag.String("httpsProxy", "", "Proxy server for HTTPS requests") ) // regular flags @@ -47,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") From 2b3cc4dccf5338f21c8925da22db275931b5cc29 Mon Sep 17 00:00:00 2001 From: Matteo Suppo Date: Thu, 26 Jul 2018 15:57:25 +0200 Subject: [PATCH 4/4] Send ini flags in a more-compatible way The flag parser was confused with flags separated by spaces, resulting in inconsistent behaviour where flags were discarded --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 3dbced61c..d091d519a 100755 --- a/main.go +++ b/main.go @@ -502,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) } }