Skip to content

Commit eb82d99

Browse files
authored
Merge pull request #104 from yashsinghcodes/fix-proxy-moca
Fixing SHUFFLE_INTERNAL_PROXY
2 parents a2756b7 + 5b74a57 commit eb82d99

File tree

2 files changed

+71
-14
lines changed

2 files changed

+71
-14
lines changed

shared.go

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23821,23 +23821,46 @@ func DecideExecution(ctx context.Context, workflowExecution WorkflowExecution, e
2382123821
return workflowExecution, relevantActions
2382223822
}
2382323823

23824-
func GetExternalClient(baseUrl string) *http.Client {
23825-
httpProxy := os.Getenv("HTTP_PROXY")
23826-
httpsProxy := os.Getenv("HTTPS_PROXY")
23824+
func HandleInternalProxy(handler *http.Client) *http.Client {
23825+
httpProxy := os.Getenv("SHUFFLE_INTERNAL_HTTP_PROXY")
23826+
httpsProxy := os.Getenv("SHUFFLE_INTERNAL_HTTPS_PROXY")
2382723827

23828-
// Look for internal proxy instead
23829-
// in case apps need a different one: https://jamboard.google.com/d/1KNr4JJXmTcH44r5j_5goQYinIe52lWzW-12Ii_joi-w/viewer?mtt=9r8nrqpnbz6z&f=0
23828+
transport := &http.Transport{}
2383023829

23831-
overrideHttpProxy := os.Getenv("SHUFFLE_INTERNAL_HTTP_PROXY")
23832-
overrideHttpsProxy := os.Getenv("SHUFFLE_INTERNAL_HTTPS_PROXY")
23833-
if len(overrideHttpProxy) > 0 && strings.ToLower(overrideHttpProxy) != "noproxy" {
23834-
httpProxy = overrideHttpProxy
23835-
}
23830+
if (len(httpProxy) > 0 || len(httpsProxy) > 0) && (strings.ToLower(httpProxy) != "noproxy" || strings.ToLower(httpsProxy) != "noproxy") {
23831+
if len(httpProxy) > 0 && strings.ToLower(httpProxy) != "noproxy" {
23832+
log.Printf("[INFO] Running with HTTP proxy %s (env: HTTP_PROXY)", httpProxy)
23833+
23834+
url_i := url.URL{}
23835+
url_proxy, err := url_i.Parse(httpProxy)
23836+
if err == nil {
23837+
transport.Proxy = http.ProxyURL(url_proxy)
23838+
}
23839+
}
23840+
23841+
if len(httpsProxy) > 0 && strings.ToLower(httpsProxy) != "noproxy" {
23842+
log.Printf("[INFO] Running with HTTPS proxy %s (env: HTTPS_PROXY)", httpsProxy)
2383623843

23837-
if len(overrideHttpsProxy) > 0 && strings.ToLower(overrideHttpsProxy) != "noproxy" {
23838-
httpsProxy = overrideHttpsProxy
23844+
url_i := url.URL{}
23845+
url_proxy, err := url_i.Parse(httpsProxy)
23846+
if err == nil {
23847+
transport.Proxy = http.ProxyURL(url_proxy)
23848+
}
23849+
}
2383923850
}
2384023851

23852+
handler.Transport = transport
23853+
23854+
return handler
23855+
}
23856+
23857+
func GetExternalClient(baseUrl string) *http.Client {
23858+
// Look for internal proxy instead
23859+
// in case apps need a different one: https://jamboard.google.com/d/1KNr4JJXmTcH44r5j_5goQYinIe52lWzW-12Ii_joi-w/viewer?mtt=9r8nrqpnbz6z&f=0
23860+
httpProxy := os.Getenv("SHUFFLE_INTERNAL_HTTP_PROXY")
23861+
httpsProxy := os.Getenv("SHUFFLE_INTERNAL_HTTPS_PROXY")
23862+
23863+
2384123864
transport := http.DefaultTransport.(*http.Transport)
2384223865
transport.MaxIdleConnsPerHost = 100
2384323866
transport.ResponseHeaderTimeout = time.Second * 60
@@ -23894,8 +23917,27 @@ func GetExternalClient(baseUrl string) *http.Client {
2389423917

2389523918
if (len(httpProxy) > 0 || len(httpsProxy) > 0) && baseUrl != "http://shuffle-backend:5001" {
2389623919
//client = &http.Client{}
23920+
if len(httpProxy) > 0 && httpProxy != "noproxy"{
23921+
log.Printf("[INFO] Running with HTTP proxy %s (env: HTTP_PROXY)", httpProxy)
23922+
23923+
url_i := url.URL{}
23924+
url_proxy, err := url_i.Parse(httpProxy)
23925+
if err == nil {
23926+
transport.Proxy = http.ProxyURL(url_proxy)
23927+
}
23928+
}
23929+
if len(httpsProxy) > 0 && httpsProxy != "noproxy"{
23930+
log.Printf("[INFO] Running with HTTPS proxy %s (env: HTTPS_PROXY)", httpsProxy)
23931+
23932+
url_i := url.URL{}
23933+
url_proxy, err := url_i.Parse(httpsProxy)
23934+
if err == nil {
23935+
transport.Proxy = http.ProxyURL(url_proxy)
23936+
}
23937+
}
2389723938
} else {
23898-
if len(httpProxy) > 0 {
23939+
// keeping this here for now
23940+
if len(httpProxy) > 0 && httpProxy != "noproxy" {
2389923941
log.Printf("[INFO] Running with HTTP proxy %s (env: HTTP_PROXY)", httpProxy)
2390023942

2390123943
url_i := url.URL{}
@@ -23904,7 +23946,7 @@ func GetExternalClient(baseUrl string) *http.Client {
2390423946
transport.Proxy = http.ProxyURL(url_proxy)
2390523947
}
2390623948
}
23907-
if len(httpsProxy) > 0 {
23949+
if len(httpsProxy) > 0 && httpsProxy != "noproxy" {
2390823950
log.Printf("[INFO] Running with HTTPS proxy %s (env: HTTPS_PROXY)", httpsProxy)
2390923951

2391023952
url_i := url.URL{}

shared_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package shuffle
22

33
import (
44
"testing"
5+
"net/http"
56
)
67

78
func TestIsLoop(t *testing.T) {
@@ -26,3 +27,17 @@ func TestIsLoop(t *testing.T) {
2627
}
2728
}
2829
}
30+
31+
// Simple Test for HandleInternalProxy(client)
32+
// set env SHUFFLE_INTERNAL_HTTP_PROXY to test the function.
33+
func TestHandleInternalProxy(t *testing.T) {
34+
client := &http.Client{}
35+
result := HandleInternalProxy(client)
36+
37+
if result.Transport.(*http.Transport).Proxy != nil {
38+
proxyURL, _ := result.Transport.(*http.Transport).Proxy(nil)
39+
t.Logf("Proxy URL set: %v", proxyURL)
40+
} else {
41+
t.Log("No proxy set")
42+
}
43+
}

0 commit comments

Comments
 (0)