Skip to content

Commit 9191b67

Browse files
committed
Improve HTTP proxy parsing and support
- Export ParseHTTPProxy and ParseSOCKSProxy functions for reuse - Add support for lowercase proxy environment variables (http_proxy, https_proxy) - Add support for ALL_PROXY environment variable - Follow convention where lowercase variables take precedence - Add http.ProxyFromEnvironment to HTTP client configuration
1 parent fb121e7 commit 9191b67

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

farcaster-go/dialers/dialers.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ func NewDialConfig() *DialConfig {
306306
enableTLS: os.Getenv("ENABLE_TLS") == "true",
307307
enableWS: os.Getenv("ENABLE_WS") == "true",
308308
enableWSS: os.Getenv("ENABLE_WSS") == "true",
309-
httpProxy: parseHTTPProxy(),
310-
socksProxy: parseSOCKSProxy(),
309+
httpProxy: ParseHTTPProxy(),
310+
socksProxy: ParseSOCKSProxy(),
311311
}
312312
}
313313

@@ -433,11 +433,27 @@ func (dc *DialConfig) Dialers(addr string, timeout time.Duration) []Dialer {
433433
return dialers
434434
}
435435

436-
func parseHTTPProxy() *url.URL {
437-
proxyURLStr := os.Getenv("HTTP_PROXY")
438-
if proxyURLStr == "" {
439-
proxyURLStr = os.Getenv("HTTPS_PROXY")
436+
func ParseHTTPProxy() *url.URL {
437+
proxyVars := []string{
438+
"HTTP_PROXY",
439+
"HTTPS_PROXY",
440+
"ALL_PROXY",
440441
}
442+
443+
var proxyURLStr string
444+
for _, varName := range proxyVars {
445+
// Convention says lowercase variables take precedence
446+
if val := os.Getenv(strings.ToLower(varName)); val != "" {
447+
proxyURLStr = val
448+
break
449+
}
450+
if val := os.Getenv(varName); val != "" {
451+
proxyURLStr = val
452+
break
453+
}
454+
455+
}
456+
441457
if proxyURLStr == "" {
442458
return nil
443459
}
@@ -453,7 +469,7 @@ func parseHTTPProxy() *url.URL {
453469
return proxyURL
454470
}
455471

456-
func parseSOCKSProxy() *url.URL {
472+
func ParseSOCKSProxy() *url.URL {
457473
proxyURLStr := os.Getenv("SOCKS5_PROXY")
458474
if proxyURLStr == "" {
459475
return nil

farconn/services/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func createHTTPClient() *http.Client {
5151
TLSClientConfig: &tls.Config{
5252
InsecureSkipVerify: skipVerify,
5353
},
54+
Proxy: http.ProxyFromEnvironment,
5455
}
5556

5657
return &http.Client{

0 commit comments

Comments
 (0)