Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
fix: http expire time should be dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
boypt committed Oct 9, 2021
1 parent 83360cb commit 331a14e
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions server/server_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ func (s *Server) webHandle(w http.ResponseWriter, r *http.Request) {
return
}

uptime := time.Unix(s.baseInfo.Uptime, 0)
cacheSince := uptime.Format(http.TimeFormat)
cacheExpire := uptime.AddDate(0, 1, 0).Format(http.TimeFormat) // 1 month expire date

pathDir := strings.SplitN(r.URL.Path[1:], "/", 2)
switch pathDir[0] {
case "search":
Expand All @@ -67,14 +63,12 @@ func (s *Server) webHandle(w http.ResponseWriter, r *http.Request) {
case "download":
s.dlfilesh.ServeHTTP(w, r)
case s.baseInfo.Version:
w.Header().Set("Last-Modified", cacheSince)
w.Header().Set("Expires", cacheExpire)
w.Header().Set("Expires", time.Now().UTC().AddDate(0, 6, 0).Format(http.TimeFormat))
w.Header().Set("Cache-Control", "max-age:290304000, public")
s.verStatich.ServeHTTP(w, r)
default:
//no match, assume static file
w.Header().Set("Last-Modified", cacheSince)
w.Header().Set("Expires", cacheExpire)
w.Header().Set("Expires", time.Now().UTC().AddDate(0, 6, 0).Format(http.TimeFormat))
w.Header().Set("Cache-Control", "max-age:290304000, public")
s.statich.ServeHTTP(w, r)
}
Expand Down

0 comments on commit 331a14e

Please sign in to comment.