parent
85e6a77f25
commit
65c172cd8d
@ -30,6 +30,7 @@ type staticsServer struct {
|
|||||||
|
|
||||||
mut sync.RWMutex
|
mut sync.RWMutex
|
||||||
theme string
|
theme string
|
||||||
|
lastThemeChange time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func newStaticsServer(theme, assetDir string) *staticsServer {
|
func newStaticsServer(theme, assetDir string) *staticsServer {
|
||||||
@ -38,6 +39,7 @@ func newStaticsServer(theme, assetDir string) *staticsServer {
|
|||||||
assets: auto.Assets(),
|
assets: auto.Assets(),
|
||||||
mut: sync.NewRWMutex(),
|
mut: sync.NewRWMutex(),
|
||||||
theme: theme,
|
theme: theme,
|
||||||
|
lastThemeChange: time.Now().UTC(),
|
||||||
}
|
}
|
||||||
|
|
||||||
seen := make(map[string]struct{})
|
seen := make(map[string]struct{})
|
||||||
@ -86,6 +88,7 @@ func (s *staticsServer) serveAsset(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
s.mut.RLock()
|
s.mut.RLock()
|
||||||
theme := s.theme
|
theme := s.theme
|
||||||
|
modificationTime := s.lastThemeChange
|
||||||
s.mut.RUnlock()
|
s.mut.RUnlock()
|
||||||
|
|
||||||
// Check for an override for the current theme.
|
// Check for an override for the current theme.
|
||||||
@ -125,14 +128,12 @@ func (s *staticsServer) serveAsset(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
etag := fmt.Sprintf("%d", auto.Generated)
|
etag := fmt.Sprintf("%d", modificationTime.Unix())
|
||||||
modified := time.Unix(auto.Generated, 0).UTC()
|
w.Header().Set("Last-Modified", modificationTime.Format(http.TimeFormat))
|
||||||
|
|
||||||
w.Header().Set("Last-Modified", modified.Format(http.TimeFormat))
|
|
||||||
w.Header().Set("Etag", etag)
|
w.Header().Set("Etag", etag)
|
||||||
|
|
||||||
if t, err := time.Parse(http.TimeFormat, r.Header.Get("If-Modified-Since")); err == nil {
|
if t, err := time.Parse(http.TimeFormat, r.Header.Get("If-Modified-Since")); err == nil {
|
||||||
if modified.Equal(t) || modified.Before(t) {
|
if modificationTime.Equal(t) || modificationTime.Before(t) {
|
||||||
w.WriteHeader(http.StatusNotModified)
|
w.WriteHeader(http.StatusNotModified)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -199,6 +200,7 @@ func (s *staticsServer) mimeTypeForFile(file string) string {
|
|||||||
func (s *staticsServer) setTheme(theme string) {
|
func (s *staticsServer) setTheme(theme string) {
|
||||||
s.mut.Lock()
|
s.mut.Lock()
|
||||||
s.theme = theme
|
s.theme = theme
|
||||||
|
s.lastThemeChange = time.Now().UTC()
|
||||||
s.mut.Unlock()
|
s.mut.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user