Skip to content

Commit 52d7cc7

Browse files
committed
Minor proxy bugfix
1 parent 536a64f commit 52d7cc7

File tree

1 file changed

+65
-26
lines changed

1 file changed

+65
-26
lines changed

shared.go

Lines changed: 65 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"io"
1111
"io/ioutil"
1212
"log"
13+
"net"
1314
"net/http"
1415
"net/url"
1516
"os"
@@ -25355,44 +25356,81 @@ func DecideExecution(ctx context.Context, workflowExecution WorkflowExecution, e
2535525356
return workflowExecution, relevantActions
2535625357
}
2535725358

25358-
func HandleInternalProxy(handler *http.Client) *http.Client {
25359-
httpProxy := os.Getenv("SHUFFLE_INTERNAL_HTTP_PROXY")
25360-
httpsProxy := os.Getenv("SHUFFLE_INTERNAL_HTTPS_PROXY")
25361-
25362-
transport := &http.Transport{}
25359+
func isNoProxyHost(noProxy, host string) bool {
25360+
// Normalize the host by removing the port if present
25361+
host, _, err := net.SplitHostPort(host)
25362+
if err != nil {
25363+
host = strings.TrimSpace(host) // Fallback to trimming
25364+
}
2536325365

25364-
if (len(httpProxy) > 0 || len(httpsProxy) > 0) && (strings.ToLower(httpProxy) != "noproxy" || strings.ToLower(httpsProxy) != "noproxy") {
25365-
if len(httpProxy) > 0 && strings.ToLower(httpProxy) != "noproxy" {
25366-
log.Printf("[INFO] Running with HTTP proxy %s (env: HTTP_PROXY)", httpProxy)
25366+
for _, noProxyEntry := range strings.Split(noProxy, ",") {
25367+
noProxyEntry = strings.TrimSpace(noProxyEntry)
2536725368

25368-
url_i := url.URL{}
25369-
url_proxy, err := url_i.Parse(httpProxy)
25370-
if err == nil {
25371-
transport.Proxy = http.ProxyURL(url_proxy)
25369+
// Handle wildcards or suffix matching
25370+
if strings.HasPrefix(noProxyEntry, ".") {
25371+
if strings.HasSuffix(host, noProxyEntry) || host == noProxyEntry[1:] {
25372+
return true
2537225373
}
25373-
}
25374-
25375-
if len(httpsProxy) > 0 && strings.ToLower(httpsProxy) != "noproxy" {
25376-
log.Printf("[INFO] Running with HTTPS proxy %s (env: HTTPS_PROXY)", httpsProxy)
25377-
25378-
url_i := url.URL{}
25379-
url_proxy, err := url_i.Parse(httpsProxy)
25380-
if err == nil {
25381-
transport.Proxy = http.ProxyURL(url_proxy)
25374+
} else if host == noProxyEntry {
25375+
// Exact match
25376+
return true
25377+
} else if ip := net.ParseIP(noProxyEntry); ip != nil {
25378+
// Handle exact IP matches
25379+
if ip.Equal(net.ParseIP(host)) {
25380+
return true
2538225381
}
2538325382
}
2538425383
}
2538525384

25386-
handler.Transport = transport
25387-
25388-
return handler
25385+
return false
2538925386
}
2539025387

2539125388
func GetExternalClient(baseUrl string) *http.Client {
2539225389
// Look for internal proxy instead
2539325390
// in case apps need a different one: https://jamboard.google.com/d/1KNr4JJXmTcH44r5j_5goQYinIe52lWzW-12Ii_joi-w/viewer?mtt=9r8nrqpnbz6z&f=0
25394-
httpProxy := os.Getenv("SHUFFLE_INTERNAL_HTTP_PROXY")
25395-
httpsProxy := os.Getenv("SHUFFLE_INTERNAL_HTTPS_PROXY")
25391+
//httpProxy := os.Getenv("SHUFFLE_INTERNAL_HTTP_PROXY")
25392+
//httpsProxy := os.Getenv("SHUFFLE_INTERNAL_HTTPS_PROXY")
25393+
25394+
httpProxy := os.Getenv("HTTP_PROXY")
25395+
httpsProxy := os.Getenv("HTTPS_PROXY")
25396+
25397+
noProxy := os.Getenv("NO_PROXY")
25398+
if len(os.Getenv("NOPROXY")) > 0 {
25399+
noProxy = os.Getenv("NOPROXY")
25400+
}
25401+
25402+
// Check if the IP in the baseUrl is a local one
25403+
parsedUrl, err := url.Parse(baseUrl)
25404+
if err == nil {
25405+
// Check if host has shuffle- as prefix
25406+
25407+
// Check until 33350 (Orborus -> Worker and Worker -> Apps)
25408+
if strings.HasSuffix(parsedUrl.Host, "shuffle-") || parsedUrl.Port() == "33333" || parsedUrl.Port() == "33334" || parsedUrl.Port() == "33335" || parsedUrl.Port() == "33336" || parsedUrl.Port() == "33337" || parsedUrl.Port() == "33338" || parsedUrl.Port() == "33339" || parsedUrl.Port() == "33340" || parsedUrl.Port() == "33341" || parsedUrl.Port() == "33342" || parsedUrl.Port() == "33343" || parsedUrl.Port() == "33344" || parsedUrl.Port() == "33345" || parsedUrl.Port() == "33346" || parsedUrl.Port() == "33347" || parsedUrl.Port() == "33348" || parsedUrl.Port() == "33349" || parsedUrl.Port() == "33350" {
25409+
25410+
log.Printf("[INFO] Running with internal proxy for %s", parsedUrl)
25411+
httpProxy = os.Getenv("SHUFFLE_INTERNAL_HTTP_PROXY")
25412+
httpsProxy = os.Getenv("SHUFFLE_INTERNAL_HTTPS_PROXY")
25413+
25414+
if len(os.Getenv("SHUFFLE_INTERNAL_NO_PROXY")) > 0 {
25415+
noProxy = os.Getenv("SHUFFLE_INTERNAL_NO_PROXY")
25416+
}
25417+
25418+
if len(os.Getenv("SHUFFLE_INTERNAL_NOPROXY")) > 0 {
25419+
noProxy = os.Getenv("SHUFFLE_INTERNAL_NOPROXY")
25420+
}
25421+
}
25422+
25423+
// Manage noproxy
25424+
if len(noProxy) > 0 {
25425+
isNoProxy := isNoProxyHost(noProxy, parsedUrl.Host)
25426+
if isNoProxy {
25427+
log.Printf("[INFO] Skipping proxy for %s", parsedUrl)
25428+
25429+
httpProxy = ""
25430+
httpsProxy = ""
25431+
}
25432+
}
25433+
}
2539625434

2539725435
transport := http.DefaultTransport.(*http.Transport)
2539825436
transport.MaxIdleConnsPerHost = 100
@@ -25448,6 +25486,7 @@ func GetExternalClient(baseUrl string) *http.Client {
2544825486
}
2544925487

2545025488
if (len(httpProxy) > 0 || len(httpsProxy) > 0) && (strings.ToLower(httpProxy) != "noproxy" || strings.ToLower(httpsProxy) != "noproxy") {
25489+
2545125490
if len(httpProxy) > 0 && strings.ToLower(httpProxy) != "noproxy" {
2545225491
log.Printf("[INFO] Running with HTTP proxy %s (env: HTTP_PROXY)", httpProxy)
2545325492

0 commit comments

Comments
 (0)