From 730df3d6c7178fc175d1f1d18b0a61e1023bcfd6 Mon Sep 17 00:00:00 2001 From: Janne Koschinski <janne@kuschku.de> Date: Fri, 7 Dec 2018 16:30:12 +0100 Subject: [PATCH] Ignore File Extensions for Images --- page_index.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/page_index.go b/page_index.go index a2dced3..06e9ca8 100644 --- a/page_index.go +++ b/page_index.go @@ -2,12 +2,22 @@ package main import ( "net/http" + "strings" ) type IndexData struct { User UserInfo } +func removeFileExtensions(path string) string { + var i = strings.IndexByte(path, '.') + if i < 0 { + return path + } else { + return path[0:i] + } +} + func pageIndex(ctx PageContext) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/" { @@ -33,6 +43,7 @@ func pageIndex(ctx PageContext) http.Handler { } else { w.Header().Set("Vary", "Accept-Encoding") w.Header().Set("Cache-Control", "public, max-age=31536000") + r.URL.Path = removeFileExtensions(r.URL.Path) ctx.Images.ServeHTTP(w, r) } }) -- GitLab