From 525b9a33476e97f5a2a006cb4e4ff7959722d467 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Thu, 28 Apr 2016 22:37:02 +0200 Subject: Add helper for checking if path ends with Slash --- domain.go | 2 +- helpers.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/domain.go b/domain.go index e274e274..46f57ed0 100644 --- a/domain.go +++ b/domain.go @@ -112,7 +112,7 @@ func (d *domain) checkPath(w http.ResponseWriter, r *http.Request, path string) switch { // If the URL doesn't end with /, send location to client - case fi.IsDir() && !strings.HasSuffix(r.URL.Path, "/"): + case fi.IsDir() && !endsWithSlash(r.URL.Path): newURL := *r.URL newURL.Path += "/" http.Redirect(w, r, newURL.String(), 302) diff --git a/helpers.go b/helpers.go index cd989b97..edcf583d 100644 --- a/helpers.go +++ b/helpers.go @@ -4,6 +4,7 @@ import ( "io/ioutil" "log" "net" + "strings" ) func readFile(file string) (result []byte) { @@ -28,3 +29,7 @@ func createSocket(addr string) (l net.Listener, fd uintptr) { fd = f.Fd() return } + +func endsWithSlash(path string) bool { + return strings.HasSuffix(path, "/") +} -- cgit v1.2.3