added offline mode

This commit is contained in:
ston1th 2022-03-14 00:06:06 +01:00
commit d2b91f2db4
4 changed files with 105 additions and 38 deletions

View file

@ -49,7 +49,7 @@ func (fs *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
r.URL.Path = upath
}
p := path.Clean(upath)
d, err := fs.fs.Stat(p)
d, offline, err := fs.fs.StatWithOffline(p)
if err != nil {
msg, code := toHTTPError(err)
http.Error(w, msg, code)
@ -82,7 +82,16 @@ func (fs *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
i := &responseInterceptor{w: w}
// TODO implement directory listing cache
offline = true
if offline {
r.Header.Del("If-Modified-Since")
r.Header.Del("Cache-Control")
}
fs.h.ServeHTTP(i, r)
if offline {
w.Header().Del("Last-Modified")
}
paths, err := i.GetPaths()
if err == io.EOF {
w.WriteHeader(i.Status())