Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle HTTPS_PROXY in http.Transport #22

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"log"
"net/http"
netUrl "net/url"
"os"
"strings"

Expand All @@ -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{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@David-Crty are your sure this should be pointer ?

Suggested change
transport := &http.Transport{
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 {
Expand Down
Loading