From 4e07c43065976f10f07fd0cff1e12308fdbe3578 Mon Sep 17 00:00:00 2001 From: soulteary Date: Mon, 13 Jun 2022 17:07:02 +0800 Subject: [PATCH] chore: allow user proxy ubuntu and debian together --- linux/rewriter.go | 7 +++---- pkgs/httpcache/cache.go | 2 +- proxy/proxy.go | 3 +-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/linux/rewriter.go b/linux/rewriter.go index f3e4442..04d0dec 100644 --- a/linux/rewriter.go +++ b/linux/rewriter.go @@ -103,16 +103,15 @@ func CreateNewRewriters(mode int) *URLRewriters { return rewriters } -func Rewrite(r *http.Request, rewriters *URLRewriters, mode int) { +func RewriteRequestByMode(r *http.Request, rewriters *URLRewriters, mode int) { uri := r.URL.String() var rewriter *URLRewriter if mode == TYPE_LINUX_DISTROS_UBUNTU { rewriter = rewriters.ubuntu - } - if mode == TYPE_LINUX_DISTROS_DEBIAN { + } else { + // mode == TYPE_LINUX_DISTROS_DEBIAN rewriter = rewriters.debian } - // TODO support both ubuntu and debian if rewriter.mirror != nil && rewriter.pattern.MatchString(uri) { r.Header.Add("Content-Location", uri) diff --git a/pkgs/httpcache/cache.go b/pkgs/httpcache/cache.go index a0d0d96..670f454 100644 --- a/pkgs/httpcache/cache.go +++ b/pkgs/httpcache/cache.go @@ -61,7 +61,7 @@ func NewMemoryCache() Cache { // NewDiskCache returns a disk-backed cache func NewDiskCache(dir string) (Cache, error) { - if err := os.MkdirAll(dir, 0600); err != nil { + if err := os.MkdirAll(dir, 0755); err != nil { return nil, err } fs, err := vfs.FS(dir) diff --git a/proxy/proxy.go b/proxy/proxy.go index 2e7032f..d086de0 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -46,8 +46,7 @@ func (ap *AptProxy) ServeHTTP(rw http.ResponseWriter, r *http.Request) { r.Header.Del("Cache-Control") if rule.Rewrite { before := r.URL.String() - mode := state.GetProxyMode() - linux.Rewrite(r, rewriter, mode) + linux.RewriteRequestByMode(r, rewriter, rule.OS) log.Printf("rewrote %q to %q", before, r.URL.String()) r.Host = r.URL.Host }