added webdav

This commit is contained in:
ston1th 2022-03-14 22:58:36 +01:00
commit 78bd754298
25 changed files with 7783 additions and 90 deletions

View file

@ -32,24 +32,26 @@ func skipLog(path string) bool {
func (fs *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s := &statusInterceptor{w: w}
w = s
defer func() {
if skipLog(r.RequestURI) {
return
}
fs.log.Info("access",
"client", r.RemoteAddr,
"method", r.Method,
"status", s.Status(),
"uri", r.RequestURI,
)
}()
if !skipLog(r.RequestURI) {
defer func() {
if s.Status() == http.StatusPartialContent {
return
}
fs.log.Info("access",
"client", r.RemoteAddr,
"method", r.Method,
"status", s.Status(),
"uri", r.RequestURI,
)
}()
}
upath := r.URL.Path
if !strings.HasPrefix(upath, "/") {
upath = "/" + upath
r.URL.Path = upath
}
p := path.Clean(upath)
d, offline, err := fs.fs.StatWithOffline(p)
d, _, err := fs.fs.StatWithOffline(p)
if err != nil {
msg, code := toHTTPError(err)
http.Error(w, msg, code)
@ -83,7 +85,7 @@ func (fs *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
i := &responseInterceptor{w: w}
// TODO implement directory listing cache
offline = true
offline := true
if offline {
r.Header.Del("If-Modified-Since")
r.Header.Del("Cache-Control")
@ -117,6 +119,5 @@ func toHTTPError(err error) (string, int) {
if errors.Is(err, stdfs.ErrPermission) {
return "403 Forbidden", http.StatusForbidden
}
// Default:
return "500 Internal Server Error", http.StatusInternalServerError
}