Improve OPTIONS handling

This commit is contained in:
Simon Ser
2020-01-17 11:41:44 +01:00
parent f4c21ca352
commit e2da5769f5
2 changed files with 31 additions and 3 deletions

View File

@@ -37,6 +37,27 @@ type backend struct {
FileSystem FileSystem
}
func (b *backend) Options(r *http.Request) ([]string, error) {
f, err := b.FileSystem.Open(r.URL.Path)
if os.IsNotExist(err) {
return []string{http.MethodOptions}, nil
} else if err != nil {
return nil, err
}
defer f.Close()
fi, err := f.Stat()
if err != nil {
return nil, err
}
if fi.IsDir() {
return []string{http.MethodOptions, "PROPFIND"}, nil
} else {
return []string{http.MethodOptions, http.MethodHead, http.MethodGet, "PROPFIND"}, nil
}
}
func (b *backend) HeadGet(w http.ResponseWriter, r *http.Request) error {
f, err := b.FileSystem.Open(r.URL.Path)
if err != nil {