mirror of
https://codeberg.org/git-pages/git-pages.git
synced 2026-08-17 09:26:04 +00:00
Allow setting custom Cache-Control headers via _headers
Before this change Cache-Control header would always be overridden, this change allows custom Cache-Control, provided Cache-Control is added to the header allow list.
This commit is contained in:
+9
-7
@@ -417,13 +417,15 @@ func getPage(w http.ResponseWriter, r *http.Request) error {
|
||||
io.Copy(w, reader)
|
||||
}
|
||||
} else {
|
||||
// consider content fresh for 60 seconds (the same as the freshness interval of
|
||||
// manifests in the S3 backend), and use stale content anyway as long as it's not
|
||||
// older than a hour; while it is cheap to handle If-Modified-Since queries
|
||||
// server-side, on the client `max-age=0, must-revalidate` causes every resource
|
||||
// to block the page load every time
|
||||
w.Header().Set("Cache-Control", "max-age=60, stale-while-revalidate=3600")
|
||||
// see https://web.dev/articles/stale-while-revalidate for details
|
||||
if _, hasCacheControl := w.Header()["Cache-Control"]; !hasCacheControl {
|
||||
// consider content fresh for 60 seconds (the same as the freshness interval of
|
||||
// manifests in the S3 backend), and use stale content anyway as long as it's not
|
||||
// older than a hour; while it is cheap to handle If-Modified-Since queries
|
||||
// server-side, on the client `max-age=0, must-revalidate` causes every resource
|
||||
// to block the page load every time
|
||||
w.Header().Set("Cache-Control", "max-age=60, stale-while-revalidate=3600")
|
||||
// see https://web.dev/articles/stale-while-revalidate for details
|
||||
}
|
||||
|
||||
// http.ServeContent handles conditional requests and range requests
|
||||
http.ServeContent(w, r, entryPath, mtime, reader)
|
||||
|
||||
Reference in New Issue
Block a user