webdav: add support for PUT to server

This commit is contained in:
Simon Ser
2020-01-21 21:19:44 +01:00
parent 45774fe572
commit 7d6de88179
4 changed files with 37 additions and 0 deletions

View File

@@ -23,6 +23,7 @@ type FileSystem interface {
Open(name string) (File, error)
Stat(name string) (os.FileInfo, error)
Readdir(name string) ([]os.FileInfo, error)
Create(name string) (io.WriteCloser, error)
}
// Handler handles WebDAV HTTP requests. It can be used to create a WebDAV
@@ -83,6 +84,20 @@ func (b *backend) HeadGet(w http.ResponseWriter, r *http.Request) error {
return nil
}
func (b *backend) Put(r *http.Request) error {
wc, err := b.FileSystem.Create(r.URL.Path)
if err != nil {
return err
}
defer wc.Close()
if _, err := io.Copy(wc, r.Body); err != nil {
return err
}
return wc.Close()
}
func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth internal.Depth) (*internal.Multistatus, error) {
fi, err := b.FileSystem.Stat(r.URL.Path)
if os.IsNotExist(err) {