fix: prevent stale web ui caching

This commit is contained in:
OpenClaw Agent
2026-09-22 04:32:22 +08:00
parent beeee8191b
commit 2c8531d9b9
2 changed files with 4 additions and 0 deletions
+3
View File
@@ -18,6 +18,9 @@ func TestRootAndAPIDoc(t *testing.T) {
if r.Code != 200 || !strings.Contains(r.Body.String(), "<title>My Files</title>") || !strings.Contains(r.Body.String(), "<strong>Hello</strong>") { if r.Code != 200 || !strings.Contains(r.Body.String(), "<title>My Files</title>") || !strings.Contains(r.Body.String(), "<strong>Hello</strong>") {
t.Fatalf("root: %d %s", r.Code, r.Body.String()) t.Fatalf("root: %d %s", r.Code, r.Body.String())
} }
if got := r.Header().Get("Cache-Control"); got != "no-store" {
t.Fatalf("root cache-control=%q", got)
}
r = httptest.NewRecorder() r = httptest.NewRecorder()
h.ServeHTTP(r, httptest.NewRequest(http.MethodGet, "/asset/api.html", nil)) h.ServeHTTP(r, httptest.NewRequest(http.MethodGet, "/asset/api.html", nil))
if r.Code != 200 || !strings.Contains(r.Body.String(), "/chfs/files") { if r.Code != 200 || !strings.Contains(r.Body.String(), "/chfs/files") {
+1
View File
@@ -1133,6 +1133,7 @@ func (s *Server) fileHandler(w http.ResponseWriter, r *http.Request) {
http.NotFound(w, r) http.NotFound(w, r)
return return
} }
w.Header().Set("Cache-Control", "no-store")
title := s.HTMLTitle title := s.HTMLTitle
if title == "" { if title == "" {
title = "CuteHttpFileServer" title = "CuteHttpFileServer"