From f2a9788c49b4511e0b384946de164595c3d59e15 Mon Sep 17 00:00:00 2001 From: MrMelon54 Date: Mon, 18 Mar 2024 21:01:18 +0000 Subject: [PATCH] Add support for HEAD method and parent folder link --- routes/dirlist.go | 3 +++ routes/dirlist.go.html | 5 +++++ routes/router.go | 2 ++ 3 files changed, 10 insertions(+) diff --git a/routes/dirlist.go b/routes/dirlist.go index 99113c6..6733c5a 100644 --- a/routes/dirlist.go +++ b/routes/dirlist.go @@ -49,6 +49,9 @@ type fileInfo struct { } func (r *routeCtx) handleDirList(rw http.ResponseWriter, req *http.Request) { + if req.Method == http.MethodHead { + return + } openDir, err := os.ReadDir(filepath.Join(r.basePath, req.URL.Path)) if err != nil { http.Error(rw, "404 Not Found", http.StatusNotFound) diff --git a/routes/dirlist.go.html b/routes/dirlist.go.html index 86d18b5..90aa6c4 100644 --- a/routes/dirlist.go.html +++ b/routes/dirlist.go.html @@ -29,6 +29,11 @@ Last Modified Size + + ../ + + + {{range .Files}} {{ .Name }} diff --git a/routes/router.go b/routes/router.go index 05fead7..64bbb02 100644 --- a/routes/router.go +++ b/routes/router.go @@ -59,8 +59,10 @@ func Router(db *database.Queries, name, basePath string, repository []string) ht rWeb := httprouter.New() rWeb.PUT("/*filepath", base.repoAuth(base.handlePut)) rWeb.GET("/", base.handleFiles) + rWeb.HEAD("/", base.handleFiles) for _, repo := range repository { rWeb.GET(path.Join("/", repo, "*filepath"), base.handleFiles) + rWeb.HEAD(path.Join("/", repo, "*filepath"), base.handleFiles) } mux := http.NewServeMux()