Skip to content

Commit

Permalink
chore: allow user proxy ubuntu and debian together
Browse files Browse the repository at this point in the history
  • Loading branch information
soulteary committed Jun 13, 2022
1 parent 25e1a6c commit 4e07c43
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
7 changes: 3 additions & 4 deletions linux/rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkgs/httpcache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 4e07c43

Please sign in to comment.