From 2328087edba042fe362a841b85d1bf7610083191 Mon Sep 17 00:00:00 2001 From: Bora Alper Date: Mon, 27 Aug 2018 20:25:41 +0300 Subject: [PATCH] magneticow: web: enable caching static resources for 24 hours --- cmd/magneticow/handlers.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/magneticow/handlers.go b/cmd/magneticow/handlers.go index 8466624..d445c3e 100644 --- a/cmd/magneticow/handlers.go +++ b/cmd/magneticow/handlers.go @@ -30,7 +30,9 @@ func rootHandler(w http.ResponseWriter, r *http.Request) { // TODO: we might as well move torrents.html into static... func torrentsHandler(w http.ResponseWriter, r *http.Request) { data := mustAsset("templates/torrents.html") - w.Header().Set("Content-Type", http.DetectContentType(data)) + w.Header().Set("Content-Type", "text/html; charset=utf-8") + // Cache static resources for a day + w.Header().Set("Cache-Control", "max-age=86400") w.Write(data) } @@ -75,7 +77,9 @@ func torrentsInfohashHandler(w http.ResponseWriter, r *http.Request) { // TODO: we might as well move statistics.html into static... func statisticsHandler(w http.ResponseWriter, r *http.Request) { data := mustAsset("templates/statistics.html") - w.Header().Set("Content-Type", http.DetectContentType(data)) + w.Header().Set("Content-Type", "text/html; charset=utf-8") + // Cache static resources for a day + w.Header().Set("Cache-Control", "max-age=86400") w.Write(data) } @@ -149,5 +153,7 @@ func staticHandler(w http.ResponseWriter, r *http.Request) { contentType = http.DetectContentType(data) } w.Header().Set("Content-Type", contentType) + // Cache static resources for a day + w.Header().Set("Cache-Control", "max-age=86400") w.Write(data) }