mirror of
https://github.com/owncast/owncast.git
synced 2025-11-03 13:01:46 +08:00
Update caching logic/headers (#184)
* Improve caching by adding etags and reducing the max-age * Move caching into middleware. Set cache headers on segments
This commit is contained in:
@ -37,21 +37,29 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// For search engine bots and social scrapers return a special
|
||||
// server-rendered page.
|
||||
if utils.IsUserAgentABot(r.UserAgent()) && isIndexRequest {
|
||||
handleScraperMetadataPage(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
// If the ETags match then return a StatusNotModified
|
||||
if responseCode := middleware.ProcessEtags(w, r); responseCode != 0 {
|
||||
w.WriteHeader(responseCode)
|
||||
return
|
||||
}
|
||||
|
||||
if path.Ext(r.URL.Path) == ".m3u8" {
|
||||
middleware.DisableCache(w)
|
||||
|
||||
clientID := utils.GenerateClientIDFromRequest(r)
|
||||
core.SetClientActive(clientID)
|
||||
} else {
|
||||
// Set a cache control header of one day
|
||||
middleware.SetCache(1, w)
|
||||
}
|
||||
|
||||
// Set a cache control max-age header
|
||||
middleware.SetCachingHeaders(w, r)
|
||||
|
||||
http.ServeFile(w, r, path.Join("webroot", r.URL.Path))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user