diff options
author | Arthur Zamarin <arthurzam@gentoo.org> | 2024-09-25 21:51:55 +0300 |
---|---|---|
committer | Arthur Zamarin <arthurzam@gentoo.org> | 2024-09-25 21:51:55 +0300 |
commit | ba04d11088676730f5b76b87923f7df60b8422e8 (patch) | |
tree | e002267e313bcbbc1c644f62afced9c24b27278e | |
parent | resolve.json: improve search quality (diff) | |
download | soko-ba04d11088676730f5b76b87923f7df60b8422e8.tar.gz soko-ba04d11088676730f5b76b87923f7df60b8422e8.tar.bz2 soko-ba04d11088676730f5b76b87923f7df60b8422e8.zip |
http: add Expires header, with 5 minutes by default
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r-- | pkg/app/serve.go | 2 | ||||
-rw-r--r-- | pkg/config/config.go | 3 |
2 files changed, 5 insertions, 0 deletions
diff --git a/pkg/app/serve.go b/pkg/app/serve.go index a263781..4f97039 100644 --- a/pkg/app/serve.go +++ b/pkg/app/serve.go @@ -17,6 +17,7 @@ import ( "soko/pkg/app/handler/useflags" "soko/pkg/config" "soko/pkg/database" + "time" ) // Serve is used to serve the web application @@ -137,6 +138,7 @@ func mw(handler http.HandlerFunc) http.HandlerFunc { // setDefaultHeaders sets the default headers that apply for all pages func setDefaultHeaders(w http.ResponseWriter) { w.Header().Set("Cache-Control", config.CacheControl()) + w.Header().Set("Expires", time.Now().UTC().Add(config.CacheTime).Format(http.TimeFormat)) } func cors(h http.Handler) http.HandlerFunc { diff --git a/pkg/config/config.go b/pkg/config/config.go index c5775c8..622c013 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -4,6 +4,7 @@ package config import ( "fmt" "os" + "time" ) func PortDir() string { @@ -70,6 +71,8 @@ func CacheControl() string { return getEnv("SOKO_CACHE_CONTROL", "max-age=300") } +const CacheTime = 5 * time.Minute + func UserAgent() string { return fmt.Sprintf("Gentoo Soko %s/packages.gentoo.org/gpackages@gentoo.org", Version()) } |