From 53f224300bf9d49e46bcd3fa428a55b28683cba8 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 11 Sep 2022 23:18:31 +0200 Subject: [PATCH] internal: set ETag header on static resources to reduce cache issues Signed-off-by: Jens Langhammer #3456 --- go.mod | 3 +++ go.sum | 6 ++++++ internal/web/static.go | 6 ++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index a9440d394..69d018f60 100644 --- a/go.mod +++ b/go.mod @@ -42,6 +42,9 @@ require ( github.com/felixge/httpsnoop v1.0.1 // indirect github.com/garyburd/redigo v1.6.2 // indirect github.com/go-asn1-ber/asn1-ber v1.5.4 // indirect + github.com/go-http-utils/etag v0.0.0-20161124023236-513ea8f21eb1 // indirect + github.com/go-http-utils/fresh v0.0.0-20161124030543-7231e26a4b27 // indirect + github.com/go-http-utils/headers v0.0.0-20181008091004-fed159eddc2a // indirect github.com/go-openapi/analysis v0.21.2 // indirect github.com/go-openapi/errors v0.20.2 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect diff --git a/go.sum b/go.sum index ee77aec8a..d30a07a60 100644 --- a/go.sum +++ b/go.sum @@ -85,6 +85,12 @@ github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6 github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-http-utils/etag v0.0.0-20161124023236-513ea8f21eb1 h1:zga7zaRE8HCbWjcXMDlfvmQtH0/kMVLo7cQ48dy6kWg= +github.com/go-http-utils/etag v0.0.0-20161124023236-513ea8f21eb1/go.mod h1:PumS+5d59wmAGsZo6IfRpVNaJUq+6xjC4Utt/k8GO6Q= +github.com/go-http-utils/fresh v0.0.0-20161124030543-7231e26a4b27 h1:O6yi4xa9b2DMosGsXzlMe2E9qXgXCVkRLCoRX+5amxI= +github.com/go-http-utils/fresh v0.0.0-20161124030543-7231e26a4b27/go.mod h1:AYvN8omj7nKLmbcXS2dyABYU6JB1Lz1bHmkkq1kf4I4= +github.com/go-http-utils/headers v0.0.0-20181008091004-fed159eddc2a h1:v6zMvHuY9yue4+QkG/HQ/W67wvtQmWJ4SDo9aK/GIno= +github.com/go-http-utils/headers v0.0.0-20181008091004-fed159eddc2a/go.mod h1:I79BieaU4fxrw4LMXby6q5OS9XnoR9UIKLOzDFjUmuw= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= diff --git a/internal/web/static.go b/internal/web/static.go index 534a839b0..5e8f721d2 100644 --- a/internal/web/static.go +++ b/internal/web/static.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" + "github.com/go-http-utils/etag" "github.com/gorilla/mux" "goauthentik.io/internal/config" "goauthentik.io/internal/constants" @@ -58,10 +59,11 @@ func (ws *WebServer) configureStatic() { } func (ws *WebServer) staticHeaderMiddleware(h http.Handler) http.Handler { + etagHandler := etag.Handler(h, false) return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Cache-Control", "\"public, no-transform\"") w.Header().Set("X-authentik-version", constants.VERSION) - w.Header().Set("Vary", "X-authentik-version") - h.ServeHTTP(w, r) + w.Header().Set("Vary", "X-authentik-version, Etag") + etagHandler.ServeHTTP(w, r) }) }