disable some more cache control in debug mode

This commit is contained in:
Ted Unangst 2019-12-04 00:44:45 -05:00
parent 9e7e4e88df
commit b679a81cb5
4 changed files with 20 additions and 14 deletions

View File

@ -21,7 +21,6 @@ import (
"github.com/mattn/go-runewidth" "github.com/mattn/go-runewidth"
) )
var skinTones = "\U0001F3FB\U0001F3FC\U0001F3FD\U0001F3FE\U0001F3FF" var skinTones = "\U0001F3FB\U0001F3FC\U0001F3FD\U0001F3FE\U0001F3FF"
var re_moredumb = regexp.MustCompile("[\U0001f44f\U0001f6a8\U000026a0][" + skinTones + "\ufe0f]*") var re_moredumb = regexp.MustCompile("[\U0001f44f\U0001f6a8\U000026a0][" + skinTones + "\ufe0f]*")

25
web.go
View File

@ -48,6 +48,8 @@ var readviews *templates.Template
var userSep = "u" var userSep = "u"
var honkSep = "h" var honkSep = "h"
var debugMode = false
func getuserstyle(u *login.UserInfo) template.CSS { func getuserstyle(u *login.UserInfo) template.CSS {
if u == nil { if u == nil {
return "" return ""
@ -223,8 +225,10 @@ func showrss(w http.ResponseWriter, r *http.Request) {
modtime = honk.Date modtime = honk.Date
} }
} }
if !debugMode {
w.Header().Set("Cache-Control", "max-age=300") w.Header().Set("Cache-Control", "max-age=300")
w.Header().Set("Last-Modified", modtime.Format(http.TimeFormat)) w.Header().Set("Last-Modified", modtime.Format(http.TimeFormat))
}
err := feed.Write(w) err := feed.Write(w)
if err != nil { if err != nil {
@ -874,7 +878,7 @@ func thelistingoftheontologies(w http.ResponseWriter, r *http.Request) {
sort.Slice(onts, func(i, j int) bool { sort.Slice(onts, func(i, j int) bool {
return onts[i].Name < onts[j].Name return onts[i].Name < onts[j].Name
}) })
if u == nil { if u == nil && !debugMode {
w.Header().Set("Cache-Control", "max-age=300") w.Header().Set("Cache-Control", "max-age=300")
} }
templinfo := getInfo(r) templinfo := getInfo(r)
@ -1093,7 +1097,7 @@ func honkpage(w http.ResponseWriter, u *login.UserInfo, honks []*Honk, templinfo
templinfo["TopHID"] = 0 templinfo["TopHID"] = 0
} }
} }
if u == nil { if u == nil && !debugMode {
w.Header().Set("Cache-Control", "max-age=60") w.Header().Set("Cache-Control", "max-age=60")
} }
err := readviews.Execute(w, "honkpage.html", templinfo) err := readviews.Execute(w, "honkpage.html", templinfo)
@ -1991,7 +1995,9 @@ func avatate(w http.ResponseWriter, r *http.Request) {
} }
func serveasset(w http.ResponseWriter, r *http.Request) { func serveasset(w http.ResponseWriter, r *http.Request) {
//w.Header().Set("Cache-Control", "max-age=7776000") if !debugMode {
w.Header().Set("Cache-Control", "max-age=7776000")
}
dir := viewDir dir := viewDir
if r.URL.Path == "/local.css" { if r.URL.Path == "/local.css" {
dir = dataDir dir = dataDir
@ -2000,7 +2006,9 @@ func serveasset(w http.ResponseWriter, r *http.Request) {
} }
func servehelp(w http.ResponseWriter, r *http.Request) { func servehelp(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"] name := mux.Vars(r)["name"]
//w.Header().Set("Cache-Control", "max-age=3600") if !debugMode {
w.Header().Set("Cache-Control", "max-age=3600")
}
http.ServeFile(w, r, viewDir+"/docs/"+name) http.ServeFile(w, r, viewDir+"/docs/"+name)
} }
func servehtml(w http.ResponseWriter, r *http.Request) { func servehtml(w http.ResponseWriter, r *http.Request) {
@ -2012,7 +2020,7 @@ func servehtml(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/about" { if r.URL.Path == "/about" {
templinfo["Sensors"] = getSensors() templinfo["Sensors"] = getSensors()
} }
if u == nil { if u == nil && !debugMode {
w.Header().Set("Cache-Control", "max-age=60") w.Header().Set("Cache-Control", "max-age=60")
} }
err := readviews.Execute(w, r.URL.Path[1:]+".html", templinfo) err := readviews.Execute(w, r.URL.Path[1:]+".html", templinfo)
@ -2229,9 +2237,8 @@ func serve() {
go redeliverator() go redeliverator()
go tracker() go tracker()
debug := false getconfig("debug", &debugMode)
getconfig("debug", &debug) readviews = templates.Load(debugMode,
readviews = templates.Load(debug,
viewDir+"/views/honkpage.html", viewDir+"/views/honkpage.html",
viewDir+"/views/honkfrags.html", viewDir+"/views/honkfrags.html",
viewDir+"/views/honkers.html", viewDir+"/views/honkers.html",
@ -2249,7 +2256,7 @@ func serve() {
viewDir+"/views/onts.html", viewDir+"/views/onts.html",
viewDir+"/views/honkpage.js", viewDir+"/views/honkpage.js",
) )
if !debug { if !debugMode {
assets := []string{viewDir + "/views/style.css", dataDir + "/views/local.css", viewDir + "/views/honkpage.js"} assets := []string{viewDir + "/views/style.css", dataDir + "/views/local.css", viewDir + "/views/honkpage.js"}
for _, s := range assets { for _, s := range assets {
savedassetparams[s] = getassetparam(s) savedassetparams[s] = getassetparam(s)