mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 16:24:14 +00:00
webdav: add support for allprop and propname in PROPFIND
This commit is contained in:
parent
ae0541654a
commit
4c4624e225
@ -197,7 +197,9 @@ func (prop *Prop) XMLNames() []xml.Name {
|
||||
type Propfind struct {
|
||||
XMLName xml.Name `xml:"DAV: propfind"`
|
||||
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 {
|
||||
@ -212,6 +214,12 @@ func NewPropNamePropfind(names ...xml.Name) *Propfind {
|
||||
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
|
||||
type ResourceType struct {
|
||||
XMLName xml.Name `xml:"DAV: resourcetype"`
|
||||
|
29
server.go
29
server.go
@ -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) {
|
||||
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() {
|
||||
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
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return nil, HTTPErrorf(http.StatusBadRequest, "webdav: propfind request missing propname, allprop or prop element")
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
|
Loading…
Reference in New Issue
Block a user