diff --git a/sumdb/handler.go b/sumdb/handler.go index 0378466..2787c8a 100644 --- a/sumdb/handler.go +++ b/sumdb/handler.go @@ -31,11 +31,6 @@ func init() { //Handler handles sumdb request func Handler(w http.ResponseWriter, r *http.Request) { - if !enableGoogleSumDB { - w.WriteHeader(http.StatusNotFound) - return - } - if strings.HasSuffix(r.URL.Path, "/supported") { for _, supported := range supportedSumDB { uri := fmt.Sprintf("/sumdb/%s/supported", supported) @@ -49,6 +44,11 @@ func Handler(w http.ResponseWriter, r *http.Request) { return } + if !enableGoogleSumDB { + sumViaGoproxy(w, r) + return + } + p := "https://" + strings.TrimPrefix(r.URL.Path, "/sumdb/") _, err := url.Parse(p) if err != nil { @@ -69,6 +69,29 @@ func Handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, err.Error()) return } + return +} +func sumViaGoproxy(w http.ResponseWriter, r *http.Request) { + p := "https://goproxy.io" + r.URL.Path + _, err := url.Parse(p) + if err != nil { + w.WriteHeader(http.StatusGone) + fmt.Fprintf(w, err.Error()) + return + } + + resp, err := http.Get(p) + if err != nil { + w.WriteHeader(http.StatusGone) + fmt.Fprintf(w, err.Error()) + return + } + defer resp.Body.Close() + w.WriteHeader(resp.StatusCode) + if _, err := io.Copy(w, resp.Body); err != nil { + fmt.Fprintf(w, err.Error()) + return + } return }