diff --git a/server/internal.go b/server/internal.go index 314e2c0..83b9e72 100644 --- a/server/internal.go +++ b/server/internal.go @@ -12,18 +12,20 @@ import ( const ( INTERNAL_PAGE_HOME string = "/" + INTERNAL_PAGE_PING = "/_/ping/" ) const ( TYPE_NOT_FOUND int = 0 TYPE_HOME = 1 + TYPE_PING = 2 ) func isInternalUrls(url string) bool { if strings.Contains(url, "ubuntu") || strings.Contains(url, "debian") { return false } - return url == INTERNAL_PAGE_HOME + return url == INTERNAL_PAGE_HOME || url == INTERNAL_PAGE_PING } func getInternalResType(url string) int { @@ -31,6 +33,10 @@ func getInternalResType(url string) int { return TYPE_HOME } + if url == INTERNAL_PAGE_PING { + return TYPE_PING + } + return TYPE_NOT_FOUND } @@ -38,9 +44,7 @@ func renderInternalUrls(url string, rw *http.ResponseWriter) { types := getInternalResType(url) if types == TYPE_NOT_FOUND { return - } - - if types == TYPE_HOME { + } else if types == TYPE_HOME { cacheSize, _ := system.DirSize("./.aptcache") files, _ := ioutil.ReadDir("./.aptcache/header/v1") available, _ := system.DiskAvailable() @@ -54,7 +58,7 @@ func renderInternalUrls(url string, rw *http.ResponseWriter) { system.HumanFileSize(memoryUsage), goroutine, )) - return + } else if types == TYPE_PING { + io.WriteString(*rw, "pong") } - } diff --git a/server/proxy.go b/server/proxy.go index 17570e2..47decc4 100644 --- a/server/proxy.go +++ b/server/proxy.go @@ -40,13 +40,8 @@ func (ap *AptProxy) ServeHTTP(rw http.ResponseWriter, r *http.Request) { var rule *linux.Rule if isInternalUrls(r.URL.Path) { rule = nil - renderInternalUrls(r.URL.Path, &rw) - - if getInternalResType(r.URL.Path) == TYPE_HOME { - rw.Header().Set("Content-Type", "text/html; charset=utf-8") - } - + rw.Header().Set("Content-Type", "text/html; charset=utf-8") } else { rule, match := linux.MatchingRule(r.URL.Path, ap.Rules) if match {