Skip to content

Commit 34a954d

Browse files
authored
Merge pull request #21 from ethpandaops/feat/configure-cache-headers
feat: configure cache headers for config, bounds, and proxy endpoints
2 parents fd99c16 + 6494f34 commit 34a954d

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

internal/api/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (h *ConfigHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
8484

8585
// Set headers.
8686
w.Header().Set("Content-Type", "application/json")
87-
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
87+
w.Header().Set("Cache-Control", "public, max-age=1, s-maxage=60, stale-while-revalidate=300")
8888

8989
// Encode response
9090
if err := json.NewEncoder(w).Encode(response); err != nil {

internal/frontend/frontend.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,8 @@ func (f *Frontend) serveIndex(w http.ResponseWriter, r *http.Request) {
173173
"content_length": len(html),
174174
}).Debug("Serving route-specific cached index.html")
175175

176-
// Set no-cache headers for index.html
177-
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
178-
w.Header().Set("Pragma", "no-cache")
179-
w.Header().Set("Expires", "0")
176+
// Set cache headers for index.html (contains config and bounds data)
177+
w.Header().Set("Cache-Control", "public, max-age=1, s-maxage=5, stale-while-revalidate=1")
180178
w.Header().Set("Content-Type", "text/html; charset=utf-8")
181179
w.WriteHeader(http.StatusOK)
182180

internal/proxy/proxy.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (p *Proxy) createReverseProxy(
135135
ExpectContinueTimeout: 1 * time.Second,
136136
}
137137

138-
// Create ReverseProxy with Rewrite function
138+
// Create ReverseProxy with Rewrite function and response modification
139139
proxy := &httputil.ReverseProxy{
140140
Rewrite: func(r *httputil.ProxyRequest) {
141141
// Set target URL
@@ -176,6 +176,12 @@ func (p *Proxy) createReverseProxy(
176176
}).Debug("Transformed slot filters to slot_start_date_time")
177177
}
178178
},
179+
ModifyResponse: func(r *http.Response) error {
180+
// Set cache headers for proxy responses
181+
r.Header.Set("Cache-Control", "public, max-age=1, s-maxage=5, stale-while-revalidate=1")
182+
183+
return nil
184+
},
179185
Transport: transport,
180186
ErrorHandler: func(w http.ResponseWriter, r *http.Request, err error) {
181187
p.logger.WithFields(logrus.Fields{

0 commit comments

Comments
 (0)