From 8759f57f1c94060a696cd5de5ea8dc66cf19713d Mon Sep 17 00:00:00 2001 From: Captain ALM Date: Tue, 12 Jul 2022 12:01:53 +0100 Subject: [PATCH] Fix the package name output when username is specified, Fixes #1 . --- outputMeta/packagemetatagoutputter.go | 6 +----- web/web.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/outputMeta/packagemetatagoutputter.go b/outputMeta/packagemetatagoutputter.go index 72f361e..5380b48 100644 --- a/outputMeta/packagemetatagoutputter.go +++ b/outputMeta/packagemetatagoutputter.go @@ -41,11 +41,7 @@ func (pkgMTO *PackageMetaTagOutputter) getPrefix(pathIn string) string { if pkgMTO.BasePath == "" { return "_" } - if pkgMTO.Username == "" { - return path.Join(pkgMTO.BasePath, pathIn) - } else { - return path.Join(pkgMTO.BasePath, pkgMTO.Username, pathIn) - } + return path.Join(pkgMTO.BasePath, pathIn) } func (pkgMTO *PackageMetaTagOutputter) getHomeURL(pathIn string) string { diff --git a/web/web.go b/web/web.go index 1498fea..94ba46c 100644 --- a/web/web.go +++ b/web/web.go @@ -26,6 +26,7 @@ func New(yaml conf.ConfigYaml) (*http.Server, map[string]*PageHandler) { } } } + router.PathPrefix("/").HandlerFunc(domainNotAllowed) if yaml.Listen.Identify { router.Use(headerMiddleware) } @@ -53,6 +54,19 @@ func runBackgroundHttp(s *http.Server) { } } +func domainNotAllowed(rw http.ResponseWriter, req *http.Request) { + if req.Method == http.MethodGet || req.Method == http.MethodHead { + writeResponseHeaderCanWriteBody(req.Method, rw, http.StatusNotFound, "Domain Not Allowed") + } else { + rw.Header().Set("Allow", http.MethodOptions+", "+http.MethodGet+", "+http.MethodHead) + if req.Method == http.MethodOptions { + writeResponseHeaderCanWriteBody(req.Method, rw, http.StatusOK, "") + } else { + writeResponseHeaderCanWriteBody(req.Method, rw, http.StatusMethodNotAllowed, "") + } + } +} + func headerMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Server", "Clerie Gilbert")