From 4c86c0a04261a4a885973955c545ecc2663b62f8 Mon Sep 17 00:00:00 2001 From: Azareal Date: Mon, 13 Aug 2018 22:01:27 +1000 Subject: [PATCH] Fixed gzip in /static/ The me endpoint is no longer served for guests. --- public/init.js | 10 ++++++---- routes/misc.go | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/public/init.js b/public/init.js index a49a8441..670ad39c 100644 --- a/public/init.js +++ b/public/init.js @@ -125,8 +125,8 @@ function fetchPhrases() { (() => { runInitHook("pre_iife"); let loggedIn = document.head.querySelector("[property='x-loggedin']").content; - - fetch("/api/me/") + if(loggedIn) { + fetch("/api/me/") .then((resp) => resp.json()) .then((data) => { console.log("loaded me endpoint data"); @@ -134,13 +134,15 @@ function fetchPhrases() { me = data; runInitHook("pre_init"); }); - - if(loggedIn) { + let toLoad = 1; loadScript("template_topics_topic.js", () => { console.log("Loaded template_topics_topic.js"); toLoad--; if(toLoad===0) fetchPhrases(); }); + } else { + me = {User:{ID:0,Session:""},Site:{"MaxRequestSize":0}}; + runInitHook("pre_init"); } })(); \ No newline at end of file diff --git a/routes/misc.go b/routes/misc.go index 8e3d8871..3d602dec 100644 --- a/routes/misc.go +++ b/routes/misc.go @@ -27,7 +27,7 @@ func StaticFile(w http.ResponseWriter, r *http.Request) { h := w.Header() // Surely, there's a more efficient way of doing this? - t, err := time.Parse(http.TimeFormat, h.Get("If-Modified-Since")) + t, err := time.Parse(http.TimeFormat, r.Header.Get("If-Modified-Since")) if err == nil && file.Info.ModTime().Before(t.Add(1*time.Second)) { w.WriteHeader(http.StatusNotModified) return @@ -36,7 +36,8 @@ func StaticFile(w http.ResponseWriter, r *http.Request) { h.Set("Content-Type", file.Mimetype) h.Set("Cache-Control", cacheControlMaxAge) //Cache-Control: max-age=31536000 h.Set("Vary", "Accept-Encoding") - if strings.Contains(h.Get("Accept-Encoding"), "gzip") { + + if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") { h.Set("Content-Encoding", "gzip") h.Set("Content-Length", strconv.FormatInt(file.GzipLength, 10)) io.Copy(w, bytes.NewReader(file.GzipData)) // Use w.Write instead?