Skip to content

Commit

Permalink
proxy sumdb with first not-direct GOPROXY
Browse files Browse the repository at this point in the history
  • Loading branch information
jan4984 committed Jul 8, 2021
1 parent 9b505e9 commit 522a9fa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
33 changes: 28 additions & 5 deletions cmd/proxy/actions/app_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ func addProxyRoutes(
}
r.HandleFunc("/index", indexHandler(indexer))

var firstGoProxyUrl *url.URL
if goBinVarProxy, has := c.GoBinaryEnvVars.GetValue("GOPROXY"); has {
for _, proxy := range strings.Split(goBinVarProxy, ",") {
if proxy == "direct" {
continue
}
firstGoProxyUrl, err = url.Parse(proxy)
if err != nil {
return err
}
}
}

for _, sumdb := range c.SumDBs {
sumdbURL, err := url.Parse(sumdb)
if err != nil {
Expand All @@ -55,11 +68,21 @@ func addProxyRoutes(
r.HandleFunc(supportPath, func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
})
sumHandler := sumdbProxy(sumdbURL, c.NoSumPatterns)
pathPrefix := "/sumdb/" + sumdbURL.Host
r.PathPrefix(pathPrefix + "/").Handler(
http.StripPrefix(strings.TrimSuffix(c.PathPrefix, "/")+pathPrefix, sumHandler),
)

var sumHandler http.Handler
if sumdbURL.Host == "sum.golang.org" && firstGoProxyUrl != nil{
pathPrefix := "/sumdb/" + sumdbURL.Host
sumdbURL.Scheme = firstGoProxyUrl.Scheme
sumdbURL.Host = firstGoProxyUrl.Host
sumHandler = sumdbProxy(sumdbURL, c.NoSumPatterns)
r.PathPrefix(pathPrefix + "/").Handler(sumHandler)
} else {
sumHandler = sumdbProxy(sumdbURL, c.NoSumPatterns)
pathPrefix := "/sumdb/" + sumdbURL.Host
r.PathPrefix(pathPrefix + "/").Handler(
http.StripPrefix(strings.TrimSuffix(c.PathPrefix, "/")+pathPrefix, sumHandler),
)
}
}

// Download Protocol
Expand Down
10 changes: 10 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ func (el EnvList) HasKey(key string) bool {
return false
}

func (el EnvList) GetValue(key string) (string, bool){
prefix := key+"="
for _, env := range el {
if strings.HasPrefix(env, prefix) {
return env[len(prefix):], true
}
}
return "", false
}

// Add adds a key=value entry to the environment
// list
func (el *EnvList) Add(key, value string) {
Expand Down

0 comments on commit 522a9fa

Please sign in to comment.