Skip to content

Add configuration setting to set proxy server #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 30 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}

Expand Down