webdav: add support for allprop and propname in PROPFIND

This commit is contained in:
Simon Ser 2020-01-15 23:03:09 +01:00
parent ae0541654a
commit 4c4624e225
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 39 additions and 4 deletions

View File

@ -195,9 +195,11 @@ func (prop *Prop) XMLNames() []xml.Name {
// https://tools.ietf.org/html/rfc4918#section-14.20 // https://tools.ietf.org/html/rfc4918#section-14.20
type Propfind struct { type Propfind struct {
XMLName xml.Name `xml:"DAV: propfind"` XMLName xml.Name `xml:"DAV: propfind"`
Prop *Prop `xml:"prop,omitempty"` Prop *Prop `xml:"prop,omitempty"`
// TODO: propname | (allprop, include?) AllProp *struct{} `xml:"allprop,omitempty"`
Include *Include `xml:"include,omitempty"`
PropName *struct{} `xml:"propname,omitempty"`
} }
func xmlNamesToRaw(names []xml.Name) []RawXMLValue { func xmlNamesToRaw(names []xml.Name) []RawXMLValue {
@ -212,6 +214,12 @@ func NewPropNamePropfind(names ...xml.Name) *Propfind {
return &Propfind{Prop: &Prop{Raw: xmlNamesToRaw(names)}} return &Propfind{Prop: &Prop{Raw: xmlNamesToRaw(names)}}
} }
// https://tools.ietf.org/html/rfc4918#section-14.8
type Include struct {
XMLName xml.Name `xml:"DAV: include"`
Raw []RawXMLValue `xml:",any"`
}
// https://tools.ietf.org/html/rfc4918#section-15.9 // https://tools.ietf.org/html/rfc4918#section-15.9
type ResourceType struct { type ResourceType struct {
XMLName xml.Name `xml:"DAV: resourcetype"` XMLName xml.Name `xml:"DAV: resourcetype"`

View File

@ -175,7 +175,32 @@ func (h *Handler) propfind(propfind *internal.Propfind, name string, fi os.FileI
func (h *Handler) propfindFile(propfind *internal.Propfind, name string, fi os.FileInfo) (*internal.Response, error) { func (h *Handler) propfindFile(propfind *internal.Propfind, name string, fi os.FileInfo) (*internal.Response, error) {
resp := internal.NewOKResponse(name) resp := internal.NewOKResponse(name)
if prop := propfind.Prop; prop != nil { if propfind.PropName != nil {
for xmlName, f := range liveProps {
emptyVal := internal.NewRawXMLElement(xmlName, nil, nil)
_, err := f(h, name, fi)
if err != nil {
continue
}
if err := resp.EncodeProp(http.StatusOK, emptyVal); err != nil {
return nil, err
}
}
} else if propfind.AllProp != nil {
// TODO: add support for propfind.Include
for _, f := range liveProps {
val, err := f(h, name, fi)
if err != nil {
continue
}
if err := resp.EncodeProp(http.StatusOK, val); err != nil {
return nil, err
}
}
} else if prop := propfind.Prop; prop != nil {
for _, xmlName := range prop.XMLNames() { for _, xmlName := range prop.XMLNames() {
emptyVal := internal.NewRawXMLElement(xmlName, nil, nil) emptyVal := internal.NewRawXMLElement(xmlName, nil, nil)
@ -202,6 +227,8 @@ func (h *Handler) propfindFile(propfind *internal.Propfind, name string, fi os.F
return nil, err return nil, err
} }
} }
} else {
return nil, HTTPErrorf(http.StatusBadRequest, "webdav: propfind request missing propname, allprop or prop element")
} }
return resp, nil return resp, nil