keep reading the docs
This commit is contained in:
parent
8edb7833a8
commit
d3a2ba9837
@ -693,7 +693,7 @@ var (
|
|||||||
errInvalidIfHeader = errors.New("webdav: invalid If header")
|
errInvalidIfHeader = errors.New("webdav: invalid If header")
|
||||||
errInvalidLockInfo = errors.New("webdav: invalid lock info")
|
errInvalidLockInfo = errors.New("webdav: invalid lock info")
|
||||||
errInvalidLockToken = errors.New("webdav: invalid lock token")
|
errInvalidLockToken = errors.New("webdav: invalid lock token")
|
||||||
errInvalidPropfind = errors.New("webdav: invalid propfind")
|
errInvalidPropfind = errors.New("webdav: invalid Propfind")
|
||||||
errInvalidProppatch = errors.New("webdav: invalid proppatch")
|
errInvalidProppatch = errors.New("webdav: invalid proppatch")
|
||||||
errInvalidResponse = errors.New("webdav: invalid response")
|
errInvalidResponse = errors.New("webdav: invalid response")
|
||||||
errInvalidTimeout = errors.New("webdav: invalid timeout")
|
errInvalidTimeout = errors.New("webdav: invalid timeout")
|
||||||
|
@ -32,7 +32,7 @@ import (
|
|||||||
// In the long term, this package should use the standard library's version
|
// In the long term, this package should use the standard library's version
|
||||||
// only, and the internal fork deleted, once
|
// only, and the internal fork deleted, once
|
||||||
// https://github.com/golang/go/issues/13400 is resolved.
|
// https://github.com/golang/go/issues/13400 is resolved.
|
||||||
ixml "tank/rest/dav/internal/xml"
|
ixml "tank/rest/dav/xml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_lockinfo
|
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_lockinfo
|
||||||
@ -134,13 +134,13 @@ func next(d *ixml.Decoder) (ixml.Token, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_prop (for propfind)
|
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_prop (for propfind)
|
||||||
type propfindProps []xml.Name
|
type PropfindProps []xml.Name
|
||||||
|
|
||||||
// UnmarshalXML appends the property names enclosed within start to pn.
|
// UnmarshalXML appends the property names enclosed within start to pn.
|
||||||
//
|
//
|
||||||
// It returns an error if start does not contain any properties or if
|
// It returns an error if start does not contain any properties or if
|
||||||
// properties contain values. Character data between properties is ignored.
|
// properties contain values. Character data between properties is ignored.
|
||||||
func (pn *propfindProps) UnmarshalXML(d *ixml.Decoder, start ixml.StartElement) error {
|
func (pn *PropfindProps) UnmarshalXML(d *ixml.Decoder, start ixml.StartElement) error {
|
||||||
for {
|
for {
|
||||||
t, err := next(d)
|
t, err := next(d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -167,39 +167,39 @@ func (pn *propfindProps) UnmarshalXML(d *ixml.Decoder, start ixml.StartElement)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_propfind
|
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_propfind
|
||||||
type propfind struct {
|
type Propfind struct {
|
||||||
XMLName ixml.Name `xml:"DAV: propfind"`
|
XMLName ixml.Name `xml:"DAV: Propfind"`
|
||||||
Allprop *struct{} `xml:"DAV: allprop"`
|
Allprop *struct{} `xml:"DAV: allprop"`
|
||||||
Propname *struct{} `xml:"DAV: propname"`
|
Propname *struct{} `xml:"DAV: propname"`
|
||||||
Prop propfindProps `xml:"DAV: prop"`
|
Prop PropfindProps `xml:"DAV: prop"`
|
||||||
Include propfindProps `xml:"DAV: include"`
|
Include PropfindProps `xml:"DAV: include"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func readPropfind(r io.Reader) (pf propfind, status int, err error) {
|
func readPropfind(r io.Reader) (pf Propfind, status int, err error) {
|
||||||
c := countingReader{r: r}
|
c := countingReader{r: r}
|
||||||
if err = ixml.NewDecoder(&c).Decode(&pf); err != nil {
|
if err = ixml.NewDecoder(&c).Decode(&pf); err != nil {
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
if c.n == 0 {
|
if c.n == 0 {
|
||||||
// An empty body means to propfind allprop.
|
// An empty body means to propfind allprop.
|
||||||
// http://www.webdav.org/specs/rfc4918.html#METHOD_PROPFIND
|
// http://www.webdav.org/specs/rfc4918.html#METHOD_PROPFIND
|
||||||
return propfind{Allprop: new(struct{})}, 0, nil
|
return Propfind{Allprop: new(struct{})}, 0, nil
|
||||||
}
|
}
|
||||||
err = errInvalidPropfind
|
err = errInvalidPropfind
|
||||||
}
|
}
|
||||||
return propfind{}, http.StatusBadRequest, err
|
return Propfind{}, http.StatusBadRequest, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if pf.Allprop == nil && pf.Include != nil {
|
if pf.Allprop == nil && pf.Include != nil {
|
||||||
return propfind{}, http.StatusBadRequest, errInvalidPropfind
|
return Propfind{}, http.StatusBadRequest, errInvalidPropfind
|
||||||
}
|
}
|
||||||
if pf.Allprop != nil && (pf.Prop != nil || pf.Propname != nil) {
|
if pf.Allprop != nil && (pf.Prop != nil || pf.Propname != nil) {
|
||||||
return propfind{}, http.StatusBadRequest, errInvalidPropfind
|
return Propfind{}, http.StatusBadRequest, errInvalidPropfind
|
||||||
}
|
}
|
||||||
if pf.Prop != nil && pf.Propname != nil {
|
if pf.Prop != nil && pf.Propname != nil {
|
||||||
return propfind{}, http.StatusBadRequest, errInvalidPropfind
|
return Propfind{}, http.StatusBadRequest, errInvalidPropfind
|
||||||
}
|
}
|
||||||
if pf.Propname == nil && pf.Allprop == nil && pf.Prop == nil {
|
if pf.Propname == nil && pf.Allprop == nil && pf.Prop == nil {
|
||||||
return propfind{}, http.StatusBadRequest, errInvalidPropfind
|
return Propfind{}, http.StatusBadRequest, errInvalidPropfind
|
||||||
}
|
}
|
||||||
return pf, 0, nil
|
return pf, 0, nil
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ func (this *DavController) HandleRoutes(writer http.ResponseWriter, request *htt
|
|||||||
|
|
||||||
path := request.URL.Path
|
path := request.URL.Path
|
||||||
|
|
||||||
//匹配 /api/webdav{subPath}
|
//匹配 /api/dav{subPath}
|
||||||
reg := regexp.MustCompile(`^/api/dav(.*)$`)
|
reg := regexp.MustCompile(`^/api/dav(.*)$`)
|
||||||
strs := reg.FindStringSubmatch(path)
|
strs := reg.FindStringSubmatch(path)
|
||||||
if len(strs) == 2 {
|
if len(strs) == 2 {
|
||||||
@ -90,11 +90,18 @@ func (this *DavController) HandleRoutes(writer http.ResponseWriter, request *htt
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//完成系统安装
|
//完成系统安装
|
||||||
func (this *DavController) Index(writer http.ResponseWriter, request *http.Request, subPath string) {
|
func (this *DavController) Index(writer http.ResponseWriter, request *http.Request, subPath string) {
|
||||||
|
|
||||||
this.logger.Info("请求访问来了:%s %s", request.RequestURI, subPath)
|
this.logger.Info("请求访问来了:%s %s", request.RequestURI, subPath)
|
||||||
|
|
||||||
|
if request.Method == "PROPFIND1" {
|
||||||
|
|
||||||
|
this.davService.HandlePropfind(writer, request)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
handler := &dav.Handler{
|
handler := &dav.Handler{
|
||||||
FileSystem: dav.Dir("/Users/fusu/d/group/golang/src/tank/tmp/dav"),
|
FileSystem: dav.Dir("/Users/fusu/d/group/golang/src/tank/tmp/dav"),
|
||||||
LockSystem: dav.NewMemLS(),
|
LockSystem: dav.NewMemLS(),
|
||||||
@ -103,3 +110,5 @@ func (this *DavController) Index(writer http.ResponseWriter, request *http.Reque
|
|||||||
handler.ServeHTTP(writer, request)
|
handler.ServeHTTP(writer, request)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package rest
|
package rest
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
//@Service
|
//@Service
|
||||||
type DavService struct {
|
type DavService struct {
|
||||||
@ -7,7 +10,6 @@ type DavService struct {
|
|||||||
matterDao *MatterDao
|
matterDao *MatterDao
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//初始化方法
|
//初始化方法
|
||||||
func (this *DavService) Init() {
|
func (this *DavService) Init() {
|
||||||
this.Bean.Init()
|
this.Bean.Init()
|
||||||
@ -17,6 +19,102 @@ func (this *DavService) Init() {
|
|||||||
if b, ok := b.(*MatterDao); ok {
|
if b, ok := b.(*MatterDao); ok {
|
||||||
this.matterDao = b
|
this.matterDao = b
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
infiniteDepth = -1
|
||||||
|
invalidDepth = -2
|
||||||
|
)
|
||||||
|
|
||||||
|
// parseDepth maps the strings "0", "1" and "infinity" to 0, 1 and
|
||||||
|
// infiniteDepth. Parsing any other string returns invalidDepth.
|
||||||
|
//
|
||||||
|
// Different WebDAV methods have further constraints on valid depths:
|
||||||
|
// - PROPFIND has no further restrictions, as per section 9.1.
|
||||||
|
// - COPY accepts only "0" or "infinity", as per section 9.8.3.
|
||||||
|
// - MOVE accepts only "infinity", as per section 9.9.2.
|
||||||
|
// - LOCK accepts only "0" or "infinity", as per section 9.10.3.
|
||||||
|
// These constraints are enforced by the handleXxx methods.
|
||||||
|
func parseDepth(s string) int {
|
||||||
|
switch s {
|
||||||
|
case "0":
|
||||||
|
return 0
|
||||||
|
case "1":
|
||||||
|
return 1
|
||||||
|
case "infinity":
|
||||||
|
return infiniteDepth
|
||||||
|
}
|
||||||
|
return invalidDepth
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//处理 方法
|
||||||
|
func (this *DavService) HandlePropfind(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
//basePath := "/Users/fusu/d/group/golang/src/tank/tmp/dav"
|
||||||
|
//
|
||||||
|
//reqPath := r.URL.Path
|
||||||
|
//
|
||||||
|
//ctx := r.Context()
|
||||||
|
//
|
||||||
|
//fi, err := os.Stat(basePath + reqPath)
|
||||||
|
//if err != nil {
|
||||||
|
// this.PanicError(err)
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//depth := infiniteDepth
|
||||||
|
//if hdr := r.Header.Get("Depth"); hdr != "" {
|
||||||
|
// depth = parseDepth(hdr)
|
||||||
|
// if depth == invalidDepth {
|
||||||
|
// this.PanicBadRequest("Depth指定错误!")
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//pf, status, err := readPropfind(r.Body)
|
||||||
|
//if err != nil {
|
||||||
|
// return status, err
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//mw := multistatusWriter{w: w}
|
||||||
|
//
|
||||||
|
//walkFn := func(reqPath string, info os.FileInfo, err error) error {
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// var pstats []Propstat
|
||||||
|
// if pf.Propname != nil {
|
||||||
|
// pnames, err := propnames(ctx, h.FileSystem, h.LockSystem, reqPath)
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// pstat := Propstat{Status: http.StatusOK}
|
||||||
|
// for _, xmlname := range pnames {
|
||||||
|
// pstat.Props = append(pstat.Props, Property{XMLName: xmlname})
|
||||||
|
// }
|
||||||
|
// pstats = append(pstats, pstat)
|
||||||
|
// } else if pf.Allprop != nil {
|
||||||
|
// pstats, err = allprop(ctx, h.FileSystem, h.LockSystem, reqPath, pf.Prop)
|
||||||
|
// } else {
|
||||||
|
// pstats, err = props(ctx, h.FileSystem, h.LockSystem, reqPath, pf.Prop)
|
||||||
|
// }
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// href := path.Join(h.Prefix, reqPath)
|
||||||
|
// if info.IsDir() {
|
||||||
|
// href += "/"
|
||||||
|
// }
|
||||||
|
// return mw.write(makePropstatResponse(href, pstats))
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//walkErr := walkFS(ctx, h.FileSystem, depth, reqPath, fi, walkFn)
|
||||||
|
//closeErr := mw.close()
|
||||||
|
//if walkErr != nil {
|
||||||
|
// return http.StatusInternalServerError, walkErr
|
||||||
|
//}
|
||||||
|
//if closeErr != nil {
|
||||||
|
// return http.StatusInternalServerError, closeErr
|
||||||
|
//}
|
||||||
|
//return 0, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user