webdav: return multistatus with 403 on PROPPATCH
This fixes a "The file cannot be accessed by the system" error when uploading some files with Windows Explorer.
This commit is contained in:
committed by
Simon Ser
parent
75c185517e
commit
87062437b6
47
server.go
47
server.go
@@ -189,8 +189,51 @@ func (b *backend) propFindFile(propfind *internal.PropFind, fi *FileInfo) (*inte
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *backend) PropPatch(r *http.Request, update *internal.PropertyUpdate) (*internal.Response, error) {
|
func (b *backend) PropPatch(r *http.Request, update *internal.PropertyUpdate) (*internal.Response, error) {
|
||||||
// TODO: return a failed Response instead
|
fi, err := b.FileSystem.Stat(r.Context(), r.URL.Path)
|
||||||
return nil, internal.HTTPErrorf(http.StatusForbidden, "webdav: PROPPATCH is unsupported")
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp := &internal.Response{Hrefs: []internal.Href{internal.Href{Path: fi.Path}}}
|
||||||
|
|
||||||
|
for _, set := range update.Set {
|
||||||
|
for _, raw := range set.Prop.Raw {
|
||||||
|
xmlName, ok := raw.XMLName()
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
emptyVal := internal.NewRawXMLElement(xmlName, nil, nil)
|
||||||
|
|
||||||
|
if err := resp.EncodeProp(http.StatusForbidden, emptyVal); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, remove := range update.Remove {
|
||||||
|
for _, raw := range remove.Prop.Raw {
|
||||||
|
xmlName, ok := raw.XMLName()
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
emptyVal := internal.NewRawXMLElement(xmlName, nil, nil)
|
||||||
|
|
||||||
|
if err := resp.EncodeProp(http.StatusForbidden, emptyVal); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(resp.PropStats) == 0 {
|
||||||
|
return nil, internal.HTTPErrorf(http.StatusBadRequest,
|
||||||
|
"webdav: request missing properties to update")
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *backend) Put(w http.ResponseWriter, r *http.Request) error {
|
func (b *backend) Put(w http.ResponseWriter, r *http.Request) error {
|
||||||
|
Reference in New Issue
Block a user