Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions master/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (m *Master) CreateWebService() {
ws := m.WebService
ws.Consumes(restful.MIME_JSON).Produces(restful.MIME_JSON)
ws.Path("/api/")
ws.Filter(m.CacheControlFilter)
ws.Filter(m.LoginFilter)

ws.Route(ws.GET("/dashboard/userinfo").To(m.handleUserInfo).
Expand Down Expand Up @@ -348,18 +349,9 @@ func noCache(h http.Handler) http.Handler {
}

func (m *Master) dashboard(response http.ResponseWriter, request *http.Request) {
// Serve static files without login check (frontend handles auth)
_, err := staticFileSystem.Open(request.RequestURI)
if request.RequestURI == "/" || os.IsNotExist(err) {
if !m.checkLogin(request) {
if m.Config.OIDC.Enable {
// Redirect to OIDC login
http.Redirect(response, request, m.oauth2Config.AuthCodeURL(""), http.StatusFound)
} else {
http.Redirect(response, request, "/login", http.StatusFound)
log.Logger().Info(fmt.Sprintf("%s %s", request.Method, request.URL), zap.Int("status_code", http.StatusFound))
}
return
}
noCache(staticFileServer).ServeHTTP(response, request)
return
}
Expand Down Expand Up @@ -2072,3 +2064,12 @@ func (m *Master) chat(response http.ResponseWriter, request *http.Request) {
}
}
}


// CacheControlFilter adds Cache-Control headers to prevent CDN caching for API endpoints
func (m *Master) CacheControlFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) {
resp.Header().Set("Cache-Control", "private, no-store, no-cache, must-revalidate")
resp.Header().Set("Pragma", "no-cache")
resp.Header().Set("Expires", "0")
chain.ProcessFilter(req, resp)
}
Loading