From ebbcb6b928e567384e21e4b8d9e119a02089c8fc Mon Sep 17 00:00:00 2001 From: Michael Melnyk Date: Mon, 7 Oct 2019 19:51:37 +0000 Subject: [PATCH] Fix issue with excluded @latest --- proxy/router.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/proxy/router.go b/proxy/router.go index a6663df..4f99906 100644 --- a/proxy/router.go +++ b/proxy/router.go @@ -115,11 +115,25 @@ func (rt *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) { rt.srv.ServeHTTP(w, r) return } + file := filepath.Join(rt.downloadRoot, r.URL.Path) if info, err := os.Stat(file); err == nil { if f, err := os.Open(file); err == nil { var ctype string defer f.Close() + if strings.HasSuffix(r.URL.Path, "/@latest") { + if time.Since(info.ModTime()) >= ListExpire { + log.Printf("------ --- %s [proxy]\n", r.URL) + rt.proxy.ServeHTTP(w, r) + } else { + ctype = "text/plain; charset=UTF-8" + w.Header().Set("Content-Type", ctype) + log.Printf("------ --- %s [cached]\n", r.URL) + http.ServeContent(w, r, "", info.ModTime(), f) + } + return + } + i := strings.Index(r.URL.Path, "/@v/") if i < 0 { http.Error(w, "no such path", http.StatusNotFound)