internal: add PROPPATCH support to server

This commit is contained in:
Simon Ser 2020-01-21 23:18:27 +01:00
parent 4cee748898
commit 90fe8dedf7
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
4 changed files with 46 additions and 0 deletions

View File

@ -261,6 +261,10 @@ func (b *backend) propfindAddressObject(propfind *internal.Propfind, ao *Address
return internal.NewPropfindResponse(ao.Href, propfind, props)
}
func (b *backend) Proppatch(r *http.Request, update *internal.Propertyupdate) (*internal.Response, error) {
panic("TODO")
}
func (b *backend) Put(r *http.Request) error {
panic("TODO")
}

View File

@ -335,3 +335,22 @@ type CurrentUserPrincipal struct {
Href string `xml:"href,omitempty"`
Unauthenticated *struct{} `xml:"unauthenticated,omitempty"`
}
// https://tools.ietf.org/html/rfc4918#section-14.19
type Propertyupdate struct {
XMLName xml.Name `xml:"DAV: propertyupdate"`
Remove []Remove `xml:"remove"`
Set []Set `xml:"set"`
}
// https://tools.ietf.org/html/rfc4918#section-14.23
type Remove struct {
XMLName xml.Name `xml:"DAV: remove"`
Prop Prop `xml:"prop"`
}
// https://tools.ietf.org/html/rfc4918#section-14.26
type Set struct {
XMLName xml.Name `xml:"DAV: set"`
Prop Prop `xml:"prop"`
}

View File

@ -77,6 +77,7 @@ type Backend interface {
Options(r *http.Request) ([]string, error)
HeadGet(w http.ResponseWriter, r *http.Request) error
Propfind(r *http.Request, pf *Propfind, depth Depth) (*Multistatus, error)
Proppatch(r *http.Request, pu *Propertyupdate) (*Response, error)
Put(r *http.Request) error
Delete(r *http.Request) error
Mkcol(r *http.Request) error
@ -112,6 +113,8 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
case "PROPFIND":
err = h.handlePropfind(w, r)
case "PROPPATCH":
err = h.handleProppatch(w, r)
case "MKCOL":
err = h.Backend.Mkcol(r)
if err == nil {
@ -236,3 +239,18 @@ func NewPropfindResponse(href string, propfind *Propfind, props map[xml.Name]Pro
return resp, nil
}
func (h *Handler) handleProppatch(w http.ResponseWriter, r *http.Request) error {
var update Propertyupdate
if err := DecodeXMLRequest(r, &update); err != nil {
return err
}
resp, err := h.Backend.Proppatch(r, &update)
if err != nil {
return err
}
ms := NewMultistatus(*resp)
return ServeMultistatus(w, ms)
}

View File

@ -185,6 +185,11 @@ func (b *backend) propfindFile(propfind *internal.Propfind, fi *FileInfo) (*inte
return internal.NewPropfindResponse(fi.Href, propfind, props)
}
func (b *backend) Proppatch(r *http.Request, update *internal.Propertyupdate) (*internal.Response, error) {
// TODO: return a failed Response instead
return nil, internal.HTTPErrorf(http.StatusForbidden, "webdav: PROPPATCH is unsupported")
}
func (b *backend) Put(r *http.Request) error {
wc, err := b.FileSystem.Create(r.URL.Path)
if err != nil {