Set a short 1 day cache duration until we do something more complex. Closes #131
This commit is contained in:
@@ -33,7 +33,7 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
// Reject requests for the web UI if it's disabled.
|
// Reject requests for the web UI if it's disabled.
|
||||||
if isIndexRequest && config.Config.DisableWebFeatures {
|
if isIndexRequest && config.Config.DisableWebFeatures {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
w.Write([]byte("404 - y u ask 4 this? If this is an error let us know: https://github.com/gabek/owncast/issues"))
|
w.Write([]byte("404 - y u ask 4 this? If this is an error let us know: https://github.com/owncast/owncast/issues"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,14 +42,17 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
http.ServeFile(w, r, path.Join("webroot", r.URL.Path))
|
|
||||||
|
|
||||||
if path.Ext(r.URL.Path) == ".m3u8" {
|
if path.Ext(r.URL.Path) == ".m3u8" {
|
||||||
middleware.DisableCache(&w)
|
middleware.DisableCache(w)
|
||||||
|
|
||||||
clientID := utils.GenerateClientIDFromRequest(r)
|
clientID := utils.GenerateClientIDFromRequest(r)
|
||||||
core.SetClientActive(clientID)
|
core.SetClientActive(clientID)
|
||||||
|
} else {
|
||||||
|
// Set a cache control header of one day
|
||||||
|
middleware.SetCache(1, w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
http.ServeFile(w, r, path.Join("webroot", r.URL.Path))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a basic HTML page with server-rendered metadata from the config file
|
// Return a basic HTML page with server-rendered metadata from the config file
|
||||||
|
|||||||
@@ -2,10 +2,18 @@ package middleware
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
//DisableCache writes the disable cache header on the responses
|
//DisableCache writes the disable cache header on the responses
|
||||||
func DisableCache(w *http.ResponseWriter) {
|
func DisableCache(w http.ResponseWriter) {
|
||||||
(*w).Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||||
(*w).Header().Set("Expires", "0")
|
w.Header().Set("Expires", "0")
|
||||||
|
}
|
||||||
|
|
||||||
|
//SetCache will set the cache control header of a response
|
||||||
|
func SetCache(days int, w http.ResponseWriter) {
|
||||||
|
seconds := strconv.Itoa(days * 86400)
|
||||||
|
w.Header().Set("Cache-Control", "max-age="+seconds)
|
||||||
|
w.Header().Set("Expires", seconds)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user