Skip to content

Commit 29763f2

Browse files
committed
Add configuration setting to set proxy server
Signed-off-by: Hanno Braun <hb@hannobraun.de>
1 parent 906c87e commit 29763f2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

config.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ appName = CreateBridge
88
updateUrl = http://downloads.arduino.cc/
99
#updateUrl = http://localhost/
1010
origins = http://webide.arduino.cc:8080
11+
#httpProxy = http://your.proxy:port # Proxy server for HTTP requests

main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var (
4747
Tools tools.Tools
4848
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")
4949
requiredToolsAPILevel = "v1"
50+
httpProxy = flag.String("httpProxy", "", "Proxy server for HTTP requests")
5051
)
5152

5253
type NullWriter int
@@ -124,6 +125,21 @@ func main() {
124125
iniflags.Parse()
125126
}
126127

128+
// If the httpProxy setting is set, use its value to override the
129+
// HTTP_PROXY environment variable. Setting this environment
130+
// variable ensures that all HTTP requests using net/http use this
131+
// proxy server.
132+
if *httpProxy != "" {
133+
log.Printf("Setting HTTP_PROXY variable to %v", *httpProxy)
134+
err := os.Setenv("HTTP_PROXY", *httpProxy)
135+
if err != nil {
136+
// The os.Setenv documentation doesn't specify how it can
137+
// fail, so I don't know how to handle this error
138+
// appropriately.
139+
panic(err)
140+
}
141+
}
142+
127143
// move CORS to config file compatibility, Vagrant version
128144
if *origins == "" {
129145
log.Println("Patching config.ini for compatibility")

0 commit comments

Comments
 (0)