mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 16:24:14 +00:00
internal: add PROPPATCH support to server
This commit is contained in:
parent
4cee748898
commit
90fe8dedf7
@ -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")
|
||||
}
|
||||
|
@ -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"`
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user