From 886f26d77aeacc75ee806a91a2098b00e0d21474 Mon Sep 17 00:00:00 2001 From: David Courtey Date: Tue, 11 Jul 2023 12:23:35 +0200 Subject: [PATCH] add HTTPS_PROXY handle --- main.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 36de864..9a31c28 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "fmt" "log" "net/http" + netUrl "net/url" "os" "strings" @@ -20,10 +21,27 @@ type roundTripper struct { func (rt roundTripper) RoundTrip(r *http.Request) (*http.Response, error) { r.Header.Set("Authorization", fmt.Sprintf("token %s", rt.accessToken)) - transport := http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: rt.insecure}} + transport := rt.getTransport() return transport.RoundTrip(r) } +func (rt roundTripper) getTransport() *http.Transport { + proxyURLStr := os.Getenv("HTTPS_PROXY") + transport := &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: rt.insecure}, + } + + if proxyURLStr != "" { + proxyURL, err := netUrl.Parse(proxyURLStr) + if err != nil { + log.Fatal("failed to parse HTTPS_PROXY:", err) + } + transport.Proxy = http.ProxyURL(proxyURL) + } + + return transport +} + func isValidState(state string) bool { validStates := [4]string{"error", "failure", "pending", "success"} for _, s := range validStates {