diff --git a/cli/cli.go b/cli/cli.go index 0f3838d..db3f024 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -3,7 +3,7 @@ package cli import ( "flag" - "github.com/soulteary/apt-proxy/linux" + Mirrors "github.com/soulteary/apt-proxy/internal/mirrors" "github.com/soulteary/apt-proxy/state" ) @@ -13,22 +13,22 @@ const ( DEFAULT_CACHE_DIR = "./.aptcache" DEFAULT_UBUNTU_MIRROR = "" // "https://mirrors.tuna.tsinghua.edu.cn/ubuntu/" DEFAULT_DEBIAN_MIRROR = "" // "https://mirrors.tuna.tsinghua.edu.cn/debian/" - DEFAULT_MODE_NAME = linux.LINUX_ALL_DISTROS + DEFAULT_MODE_NAME = Mirrors.LINUX_ALL_DISTROS DEFAULT_DEBUG = false ) var Version string func getProxyMode(mode string) int { - if mode == linux.LINUX_DISTROS_UBUNTU { - return linux.TYPE_LINUX_DISTROS_UBUNTU + if mode == Mirrors.LINUX_DISTROS_UBUNTU { + return Mirrors.TYPE_LINUX_DISTROS_UBUNTU } - if mode == linux.LINUX_DISTROS_DEBIAN { - return linux.TYPE_LINUX_DISTROS_DEBIAN + if mode == Mirrors.LINUX_DISTROS_DEBIAN { + return Mirrors.TYPE_LINUX_DISTROS_DEBIAN } - return linux.TYPE_LINUX_ALL_DISTROS + return Mirrors.TYPE_LINUX_ALL_DISTROS } func ParseFlags() (appFlags AppFlags) { diff --git a/cli/cli_test.go b/cli/cli_test.go index adaf438..45c7111 100644 --- a/cli/cli_test.go +++ b/cli/cli_test.go @@ -4,19 +4,19 @@ import ( "os" "testing" - "github.com/soulteary/apt-proxy/linux" + Mirrors "github.com/soulteary/apt-proxy/internal/mirrors" ) func TestGetProxyMode(t *testing.T) { - if getProxyMode("not-support-os") != linux.TYPE_LINUX_ALL_DISTROS { + if getProxyMode("not-support-os") != Mirrors.TYPE_LINUX_ALL_DISTROS { t.Fatal("Incorrect return default value") } - if getProxyMode(linux.LINUX_DISTROS_DEBIAN) != linux.TYPE_LINUX_DISTROS_DEBIAN { + if getProxyMode(Mirrors.LINUX_DISTROS_DEBIAN) != Mirrors.TYPE_LINUX_DISTROS_DEBIAN { t.Fatal("Incorrect return value") } - if getProxyMode(linux.LINUX_DISTROS_UBUNTU) != linux.TYPE_LINUX_DISTROS_UBUNTU { + if getProxyMode(Mirrors.LINUX_DISTROS_UBUNTU) != Mirrors.TYPE_LINUX_DISTROS_UBUNTU { t.Fatal("Incorrect return value") } } diff --git a/linux/benchmark.go b/internal/mirrors/benchmark.go similarity index 95% rename from linux/benchmark.go rename to internal/mirrors/benchmark.go index b366cdf..398e41d 100644 --- a/linux/benchmark.go +++ b/internal/mirrors/benchmark.go @@ -1,4 +1,4 @@ -package linux +package mirrors import ( "errors" @@ -40,7 +40,7 @@ type benchmarkResult struct { Duration time.Duration } -func getTheFastestMirror(mirrors []string, testUrl string) (string, error) { +func GetTheFastestMirror(mirrors []string, testUrl string) (string, error) { ch := make(chan benchmarkResult) log.Printf("Start benchmarking mirrors") // kick off all benchmarks in parallel diff --git a/linux/benchmark_test.go b/internal/mirrors/benchmark_test.go similarity index 70% rename from linux/benchmark_test.go rename to internal/mirrors/benchmark_test.go index 07d85fd..e3db454 100644 --- a/linux/benchmark_test.go +++ b/internal/mirrors/benchmark_test.go @@ -1,4 +1,4 @@ -package linux +package mirrors import ( "log" @@ -14,8 +14,8 @@ func TestResourceBenchmark(t *testing.T) { } func TestMirrorsBenchmark(t *testing.T) { - mirrors := getGeoMirrorUrlsByMode(TYPE_LINUX_DISTROS_UBUNTU) - mirror, err := getTheFastestMirror(mirrors, UBUNTU_BENCHMAKR_URL) + mirrors := GetGeoMirrorUrlsByMode(TYPE_LINUX_DISTROS_UBUNTU) + mirror, err := GetTheFastestMirror(mirrors, UBUNTU_BENCHMAKR_URL) if err != nil { t.Fatal(err) } diff --git a/linux/common.go b/internal/mirrors/common.go similarity index 96% rename from linux/common.go rename to internal/mirrors/common.go index 2a14bc3..7b10b4f 100644 --- a/linux/common.go +++ b/internal/mirrors/common.go @@ -1,6 +1,9 @@ -package linux +package mirrors -import "regexp" +import ( + "fmt" + "regexp" +) const ( LINUX_ALL_DISTROS string = "all" @@ -110,3 +113,8 @@ var UBUNTU_DEFAULT_CACHE_RULES = []Rule{ // Add file file hash {Pattern: regexp.MustCompile(`/by-hash/`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, } + +func (r *Rule) String() string { + return fmt.Sprintf("%s Cache-Control=%s Rewrite=%#v", + r.Pattern.String(), r.CacheControl, r.Rewrite) +} diff --git a/internal/mirrors/mirrors.go b/internal/mirrors/mirrors.go index ae58ef3..eeca9dd 100644 --- a/internal/mirrors/mirrors.go +++ b/internal/mirrors/mirrors.go @@ -1,5 +1,11 @@ package mirrors +import ( + "bufio" + "net/http" + "regexp" +) + type buildin_custom_mirror struct { url string alias string @@ -34,3 +40,45 @@ func GetCentOSMirrorByAliases(alias string) string { } return "" } + +func GetGeoMirrorUrlsByMode(mode int) (mirrors []string) { + if mode == TYPE_LINUX_DISTROS_UBUNTU { + ubuntuMirrorsOnline, err := getUbuntuMirrorUrlsByGeo() + if err != nil { + return BUILDIN_OFFICAL_UBUNTU_MIRRORS + } + return ubuntuMirrorsOnline + } + + if mode == TYPE_LINUX_DISTROS_DEBIAN { + return BUILDIN_OFFICAL_DEBIAN_MIRRORS + } + + mirrors = append(mirrors, BUILDIN_OFFICAL_UBUNTU_MIRRORS...) + mirrors = append(mirrors, BUILDIN_OFFICAL_DEBIAN_MIRRORS...) + return mirrors +} + +func getUbuntuMirrorUrlsByGeo() (mirrors []string, err error) { + response, err := http.Get(UBUNTU_GEO_MIRROR_API) + if err != nil { + return mirrors, err + } + + defer response.Body.Close() + scanner := bufio.NewScanner(response.Body) + + for scanner.Scan() { + mirrors = append(mirrors, scanner.Text()) + } + + return mirrors, scanner.Err() +} + +func GetPredefinedConfiguration(proxyMode int) (string, *regexp.Regexp) { + if proxyMode == TYPE_LINUX_DISTROS_UBUNTU { + return UBUNTU_BENCHMAKR_URL, UBUNTU_HOST_PATTERN + } else { + return DEBIAN_BENCHMAKR_URL, DEBIAN_HOST_PATTERN + } +} diff --git a/linux/mirrors_test.go b/internal/mirrors/mirrors_test.go similarity index 78% rename from linux/mirrors_test.go rename to internal/mirrors/mirrors_test.go index 121ce12..e68ea51 100644 --- a/linux/mirrors_test.go +++ b/internal/mirrors/mirrors_test.go @@ -1,4 +1,4 @@ -package linux +package mirrors import ( "testing" @@ -16,24 +16,24 @@ func TestGetGeoMirrors(t *testing.T) { } func TestGetMirrorUrlsByGeo(t *testing.T) { - mirrors := getGeoMirrorUrlsByMode(TYPE_LINUX_ALL_DISTROS) + mirrors := GetGeoMirrorUrlsByMode(TYPE_LINUX_ALL_DISTROS) if len(mirrors) == 0 { t.Fatal("No mirrors found") } - mirrors = getGeoMirrorUrlsByMode(TYPE_LINUX_DISTROS_DEBIAN) + mirrors = GetGeoMirrorUrlsByMode(TYPE_LINUX_DISTROS_DEBIAN) if len(mirrors) != len(BUILDIN_OFFICAL_DEBIAN_MIRRORS) { t.Fatal("Get mirrors error") } - mirrors = getGeoMirrorUrlsByMode(TYPE_LINUX_DISTROS_UBUNTU) + mirrors = GetGeoMirrorUrlsByMode(TYPE_LINUX_DISTROS_UBUNTU) if len(mirrors) == 0 { t.Fatal("No mirrors found") } } func TestGetPredefinedConfiguration(t *testing.T) { - res, pattern := getPredefinedConfiguration(TYPE_LINUX_DISTROS_UBUNTU) + res, pattern := GetPredefinedConfiguration(TYPE_LINUX_DISTROS_UBUNTU) if res != UBUNTU_BENCHMAKR_URL { t.Fatal("Failed to get resource link") } @@ -47,7 +47,7 @@ func TestGetPredefinedConfiguration(t *testing.T) { t.Fatal("Failed to verify domain name rules") } - res, pattern = getPredefinedConfiguration(TYPE_LINUX_DISTROS_DEBIAN) + res, pattern = GetPredefinedConfiguration(TYPE_LINUX_DISTROS_DEBIAN) if res != DEBIAN_BENCHMAKR_URL { t.Fatal("Failed to get resource link") } diff --git a/linux/rewriter.go b/internal/rewriter/rewriter.go similarity index 66% rename from linux/rewriter.go rename to internal/rewriter/rewriter.go index 735d149..3e015eb 100644 --- a/linux/rewriter.go +++ b/internal/rewriter/rewriter.go @@ -1,12 +1,12 @@ -package linux +package rewriter import ( - "fmt" "log" "net/http" "net/url" "regexp" + Mirrors "github.com/soulteary/apt-proxy/internal/mirrors" "github.com/soulteary/apt-proxy/state" ) @@ -20,23 +20,23 @@ type URLRewriter struct { pattern *regexp.Regexp } -func GetRewriteRulesByMode(mode int) (rules []Rule) { - if mode == TYPE_LINUX_DISTROS_UBUNTU { - return UBUNTU_DEFAULT_CACHE_RULES +func GetRewriteRulesByMode(mode int) (rules []Mirrors.Rule) { + if mode == Mirrors.TYPE_LINUX_DISTROS_UBUNTU { + return Mirrors.UBUNTU_DEFAULT_CACHE_RULES } - if mode == TYPE_LINUX_DISTROS_DEBIAN { - return DEBIAN_DEFAULT_CACHE_RULES + if mode == Mirrors.TYPE_LINUX_DISTROS_DEBIAN { + return Mirrors.DEBIAN_DEFAULT_CACHE_RULES } - rules = append(rules, UBUNTU_DEFAULT_CACHE_RULES...) - rules = append(rules, DEBIAN_DEFAULT_CACHE_RULES...) + rules = append(rules, Mirrors.UBUNTU_DEFAULT_CACHE_RULES...) + rules = append(rules, Mirrors.DEBIAN_DEFAULT_CACHE_RULES...) return rules } func getRewriterForDebian() *URLRewriter { u := &URLRewriter{} debianMirror := state.GetDebianMirror() - benchmarkUrl, pattern := getPredefinedConfiguration(TYPE_LINUX_DISTROS_DEBIAN) + benchmarkUrl, pattern := Mirrors.GetPredefinedConfiguration(Mirrors.TYPE_LINUX_DISTROS_DEBIAN) u.pattern = pattern if debianMirror != nil { @@ -45,8 +45,8 @@ func getRewriterForDebian() *URLRewriter { return u } - mirrors := getGeoMirrorUrlsByMode(TYPE_LINUX_DISTROS_DEBIAN) - fastest, err := getTheFastestMirror(mirrors, benchmarkUrl) + mirrors := Mirrors.GetGeoMirrorUrlsByMode(Mirrors.TYPE_LINUX_DISTROS_DEBIAN) + fastest, err := Mirrors.GetTheFastestMirror(mirrors, benchmarkUrl) if err != nil { log.Println("Error finding fastest mirror", err) } @@ -62,7 +62,7 @@ func getRewriterForDebian() *URLRewriter { func getRewriterForUbuntu() *URLRewriter { u := &URLRewriter{} ubuntuMirror := state.GetUbuntuMirror() - benchmarkUrl, pattern := getPredefinedConfiguration(TYPE_LINUX_DISTROS_UBUNTU) + benchmarkUrl, pattern := Mirrors.GetPredefinedConfiguration(Mirrors.TYPE_LINUX_DISTROS_UBUNTU) u.pattern = pattern if ubuntuMirror != nil { @@ -71,8 +71,8 @@ func getRewriterForUbuntu() *URLRewriter { return u } - mirrors := getGeoMirrorUrlsByMode(TYPE_LINUX_DISTROS_UBUNTU) - fastest, err := getTheFastestMirror(mirrors, benchmarkUrl) + mirrors := Mirrors.GetGeoMirrorUrlsByMode(Mirrors.TYPE_LINUX_DISTROS_UBUNTU) + fastest, err := Mirrors.GetTheFastestMirror(mirrors, benchmarkUrl) if err != nil { log.Println("Error finding fastest mirror", err) } @@ -88,12 +88,12 @@ func getRewriterForUbuntu() *URLRewriter { func CreateNewRewriters(mode int) *URLRewriters { rewriters := &URLRewriters{} - if mode == TYPE_LINUX_DISTROS_DEBIAN { + if mode == Mirrors.TYPE_LINUX_DISTROS_DEBIAN { rewriters.debian = getRewriterForDebian() return rewriters } - if mode == TYPE_LINUX_DISTROS_UBUNTU { + if mode == Mirrors.TYPE_LINUX_DISTROS_UBUNTU { rewriters.ubuntu = getRewriterForUbuntu() return rewriters } @@ -106,7 +106,7 @@ func CreateNewRewriters(mode int) *URLRewriters { func RewriteRequestByMode(r *http.Request, rewriters *URLRewriters, mode int) { uri := r.URL.String() var rewriter *URLRewriter - if mode == TYPE_LINUX_DISTROS_UBUNTU { + if mode == Mirrors.TYPE_LINUX_DISTROS_UBUNTU { rewriter = rewriters.ubuntu } else { // mode == TYPE_LINUX_DISTROS_DEBIAN @@ -126,7 +126,7 @@ func RewriteRequestByMode(r *http.Request, rewriters *URLRewriters, mode int) { } } -func MatchingRule(subject string, rules []Rule) (*Rule, bool) { +func MatchingRule(subject string, rules []Mirrors.Rule) (*Mirrors.Rule, bool) { for _, rule := range rules { if rule.Pattern.MatchString(subject) { return &rule, true @@ -134,8 +134,3 @@ func MatchingRule(subject string, rules []Rule) (*Rule, bool) { } return nil, false } - -func (r *Rule) String() string { - return fmt.Sprintf("%s Cache-Control=%s Rewrite=%#v", - r.Pattern.String(), r.CacheControl, r.Rewrite) -} diff --git a/linux/rewriter_test.go b/internal/rewriter/rewriter_test.go similarity index 66% rename from linux/rewriter_test.go rename to internal/rewriter/rewriter_test.go index db766f9..68fdb85 100644 --- a/linux/rewriter_test.go +++ b/internal/rewriter/rewriter_test.go @@ -1,26 +1,27 @@ -package linux +package rewriter import ( "strings" "testing" "time" + Mirrors "github.com/soulteary/apt-proxy/internal/mirrors" "github.com/soulteary/apt-proxy/state" ) func TestGetRewriteRulesByMode(t *testing.T) { - rules := GetRewriteRulesByMode(TYPE_LINUX_DISTROS_UBUNTU) - if rules[0].Pattern != UBUNTU_DEFAULT_CACHE_RULES[0].Pattern { + rules := GetRewriteRulesByMode(Mirrors.TYPE_LINUX_DISTROS_UBUNTU) + if rules[0].Pattern != Mirrors.UBUNTU_DEFAULT_CACHE_RULES[0].Pattern { t.Fatal("Pattern Not Match") } - rules = GetRewriteRulesByMode(TYPE_LINUX_DISTROS_DEBIAN) - if rules[0].Pattern != DEBIAN_DEFAULT_CACHE_RULES[0].Pattern { + rules = GetRewriteRulesByMode(Mirrors.TYPE_LINUX_DISTROS_DEBIAN) + if rules[0].Pattern != Mirrors.DEBIAN_DEFAULT_CACHE_RULES[0].Pattern { t.Fatal("Pattern Not Match") } - rules = GetRewriteRulesByMode(TYPE_LINUX_ALL_DISTROS) - if len(rules) != (len(DEBIAN_DEFAULT_CACHE_RULES) + len(UBUNTU_DEFAULT_CACHE_RULES)) { + rules = GetRewriteRulesByMode(Mirrors.TYPE_LINUX_ALL_DISTROS) + if len(rules) != (len(Mirrors.DEBIAN_DEFAULT_CACHE_RULES) + len(Mirrors.UBUNTU_DEFAULT_CACHE_RULES)) { t.Fatal("Pattern Length Not Match") } } @@ -40,8 +41,8 @@ func TestGetRewriterForUbuntu(t *testing.T) { } func TestCreateNewRewritersForUbuntu(t *testing.T) { - ap := *CreateNewRewriters(TYPE_LINUX_DISTROS_UBUNTU) - time.Sleep((BENCHMARK_DETECT_TIMEOUT / 2) * time.Second) + ap := *CreateNewRewriters(Mirrors.TYPE_LINUX_DISTROS_UBUNTU) + time.Sleep((Mirrors.BENCHMARK_DETECT_TIMEOUT / 2) * time.Second) if len(ap.ubuntu.mirror.Path) == 0 { t.Fatal("No mirrors found") @@ -53,8 +54,8 @@ func TestCreateNewRewritersForUbuntu(t *testing.T) { } func TestCreateNewRewritersForDebian(t *testing.T) { - ap := *CreateNewRewriters(TYPE_LINUX_DISTROS_DEBIAN) - time.Sleep((BENCHMARK_DETECT_TIMEOUT / 2) * time.Second) + ap := *CreateNewRewriters(Mirrors.TYPE_LINUX_DISTROS_DEBIAN) + time.Sleep((Mirrors.BENCHMARK_DETECT_TIMEOUT / 2) * time.Second) if len(ap.debian.mirror.Path) == 0 { t.Fatal("No mirrors found") @@ -66,8 +67,8 @@ func TestCreateNewRewritersForDebian(t *testing.T) { } func TestCreateNewRewritersForAll(t *testing.T) { - ap := *CreateNewRewriters(TYPE_LINUX_ALL_DISTROS) - time.Sleep((BENCHMARK_DETECT_TIMEOUT / 2) * time.Second) + ap := *CreateNewRewriters(Mirrors.TYPE_LINUX_ALL_DISTROS) + time.Sleep((Mirrors.BENCHMARK_DETECT_TIMEOUT / 2) * time.Second) if len(ap.debian.mirror.Path) == 0 || len(ap.ubuntu.mirror.Host) == 0 { t.Fatal("No mirrors found") @@ -81,7 +82,7 @@ func TestCreateNewRewritersForAll(t *testing.T) { func TestCreateNewRewritersWithSpecifyMirror(t *testing.T) { state.SetUbuntuMirror("https://mirrors.tuna.tsinghua.edu.cn/ubuntu/") - ap := *CreateNewRewriters(TYPE_LINUX_DISTROS_UBUNTU) + ap := *CreateNewRewriters(Mirrors.TYPE_LINUX_DISTROS_UBUNTU) if ap.ubuntu.mirror.Host != "mirrors.tuna.tsinghua.edu.cn" { t.Fatal("Mirror host incorrect") } @@ -94,14 +95,14 @@ func TestCreateNewRewritersWithSpecifyMirror(t *testing.T) { } func TestMatchingRule(t *testing.T) { - _, match := MatchingRule("http://archive.ubuntu.com/ubuntu/InRelease", UBUNTU_DEFAULT_CACHE_RULES) + _, match := MatchingRule("http://archive.ubuntu.com/ubuntu/InRelease", Mirrors.UBUNTU_DEFAULT_CACHE_RULES) if !match { t.Fatal("test ap rules faild") } } func TestRuleToString(t *testing.T) { - rule, _ := MatchingRule("http://archive.ubuntu.com/ubuntu/InRelease", UBUNTU_DEFAULT_CACHE_RULES) + rule, _ := MatchingRule("http://archive.ubuntu.com/ubuntu/InRelease", Mirrors.UBUNTU_DEFAULT_CACHE_RULES) if rule.String() != "Release(\\.gpg)?$ Cache-Control=max-age=3600 Rewrite=true" { t.Fatal("test rules toString faild") } diff --git a/linux/mirrors.go b/linux/mirrors.go deleted file mode 100644 index 8351bc7..0000000 --- a/linux/mirrors.go +++ /dev/null @@ -1,49 +0,0 @@ -package linux - -import ( - "bufio" - "net/http" - "regexp" -) - -func getGeoMirrorUrlsByMode(mode int) (mirrors []string) { - if mode == TYPE_LINUX_DISTROS_UBUNTU { - ubuntuMirrorsOnline, err := getUbuntuMirrorUrlsByGeo() - if err != nil { - return BUILDIN_OFFICAL_UBUNTU_MIRRORS - } - return ubuntuMirrorsOnline - } - - if mode == TYPE_LINUX_DISTROS_DEBIAN { - return BUILDIN_OFFICAL_DEBIAN_MIRRORS - } - - mirrors = append(mirrors, BUILDIN_OFFICAL_UBUNTU_MIRRORS...) - mirrors = append(mirrors, BUILDIN_OFFICAL_DEBIAN_MIRRORS...) - return mirrors -} - -func getUbuntuMirrorUrlsByGeo() (mirrors []string, err error) { - response, err := http.Get(UBUNTU_GEO_MIRROR_API) - if err != nil { - return mirrors, err - } - - defer response.Body.Close() - scanner := bufio.NewScanner(response.Body) - - for scanner.Scan() { - mirrors = append(mirrors, scanner.Text()) - } - - return mirrors, scanner.Err() -} - -func getPredefinedConfiguration(proxyMode int) (string, *regexp.Regexp) { - if proxyMode == TYPE_LINUX_DISTROS_UBUNTU { - return UBUNTU_BENCHMAKR_URL, UBUNTU_HOST_PATTERN - } else { - return DEBIAN_BENCHMAKR_URL, DEBIAN_HOST_PATTERN - } -} diff --git a/server/proxy.go b/server/proxy.go index 47decc4..d3a2642 100644 --- a/server/proxy.go +++ b/server/proxy.go @@ -6,11 +6,12 @@ import ( "net/http/httputil" "time" - "github.com/soulteary/apt-proxy/linux" + Mirrors "github.com/soulteary/apt-proxy/internal/mirrors" + Rewriter "github.com/soulteary/apt-proxy/internal/rewriter" "github.com/soulteary/apt-proxy/state" ) -var rewriter *linux.URLRewriters +var rewriter *Rewriter.URLRewriters var defaultTransport http.RoundTripper = &http.Transport{ Proxy: http.ProxyFromEnvironment, @@ -20,15 +21,15 @@ var defaultTransport http.RoundTripper = &http.Transport{ type AptProxy struct { Handler http.Handler - Rules []linux.Rule + Rules []Mirrors.Rule } func CreateAptProxyRouter() *AptProxy { mode := state.GetProxyMode() - rewriter = linux.CreateNewRewriters(mode) + rewriter = Rewriter.CreateNewRewriters(mode) return &AptProxy{ - Rules: linux.GetRewriteRulesByMode(mode), + Rules: Rewriter.GetRewriteRulesByMode(mode), Handler: &httputil.ReverseProxy{ Director: func(r *http.Request) {}, Transport: defaultTransport, @@ -37,18 +38,18 @@ func CreateAptProxyRouter() *AptProxy { } func (ap *AptProxy) ServeHTTP(rw http.ResponseWriter, r *http.Request) { - var rule *linux.Rule + var rule *Mirrors.Rule if isInternalUrls(r.URL.Path) { rule = nil renderInternalUrls(r.URL.Path, &rw) rw.Header().Set("Content-Type", "text/html; charset=utf-8") } else { - rule, match := linux.MatchingRule(r.URL.Path, ap.Rules) + rule, match := Rewriter.MatchingRule(r.URL.Path, ap.Rules) if match { r.Header.Del("Cache-Control") if rule.Rewrite { before := r.URL.String() - linux.RewriteRequestByMode(r, rewriter, rule.OS) + Rewriter.RewriteRequestByMode(r, rewriter, rule.OS) log.Printf("rewrote %q to %q", before, r.URL.String()) r.Host = r.URL.Host } @@ -59,7 +60,7 @@ func (ap *AptProxy) ServeHTTP(rw http.ResponseWriter, r *http.Request) { type responseWriter struct { http.ResponseWriter - rule *linux.Rule + rule *Mirrors.Rule } func (rw *responseWriter) WriteHeader(status int) {