mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 04:07:31 +00:00
fix: do not cache api (incl. grpc) and http errors (#2088)
* fix: add cache-control headers (no-store, no-cache) on grpc (for grpc-web) * fix: do not cache api response (incl. grpc) and http errors
This commit is contained in:
@@ -81,11 +81,29 @@ func AssetsCacheInterceptor(maxAge, sharedMaxAge time.Duration, h http.Handler)
|
||||
|
||||
func CacheInterceptorOpts(h http.Handler, cache *Cache) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
cache.serializeHeaders(w)
|
||||
h.ServeHTTP(w, req)
|
||||
cachingResponseWriter := &cachingResponseWriter{
|
||||
ResponseWriter: w,
|
||||
Cache: cache,
|
||||
}
|
||||
h.ServeHTTP(cachingResponseWriter, req)
|
||||
})
|
||||
}
|
||||
|
||||
type cachingResponseWriter struct {
|
||||
http.ResponseWriter
|
||||
*Cache
|
||||
}
|
||||
|
||||
func (w *cachingResponseWriter) WriteHeader(code int) {
|
||||
if code >= 400 {
|
||||
NeverCacheOptions.serializeHeaders(w.ResponseWriter)
|
||||
w.ResponseWriter.WriteHeader(code)
|
||||
return
|
||||
}
|
||||
w.Cache.serializeHeaders(w.ResponseWriter)
|
||||
w.ResponseWriter.WriteHeader(code)
|
||||
}
|
||||
|
||||
func (c *Cache) serializeHeaders(w http.ResponseWriter) {
|
||||
control := make([]string, 0, 6)
|
||||
pragma := false
|
||||
|
Reference in New Issue
Block a user