MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / handlePropfind

Method handlePropfind

server/webdav/webdav.go:713–794  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

711}
712
713func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) (status int, err error) {
714 reqPath, status, err := h.stripPrefix(r.URL.Path)
715 if err != nil {
716 return status, err
717 }
718 ctx := r.Context()
719 userAgent := r.Header.Get("User-Agent")
720 ctx = context.WithValue(ctx, conf.UserAgentKey, userAgent)
721 user := ctx.Value(conf.UserKey).(*model.User)
722 password, _ := ctx.Value(conf.MetaPassKey).(string)
723 reqPath, err = user.JoinPath(reqPath)
724 if err != nil {
725 return http.StatusForbidden, err
726 }
727 meta, err := op.GetNearestMeta(reqPath)
728 if err != nil && !errors.Is(errors.Cause(err), errs.MetaNotFound) {
729 return http.StatusInternalServerError, err
730 }
731 if !common.CanAccess(user, meta, reqPath, password) {
732 return http.StatusForbidden, errs.PermissionDenied
733 }
734 fi, err := fs.Get(ctx, reqPath, &fs.GetArgs{})
735 if err != nil {
736 if errs.IsNotFoundError(err) {
737 return http.StatusNotFound, err
738 }
739 return http.StatusMethodNotAllowed, err
740 }
741 depth := infiniteDepth
742 if hdr := r.Header.Get("Depth"); hdr != "" {
743 depth = parseDepth(hdr)
744 if depth == invalidDepth {
745 return http.StatusBadRequest, errInvalidDepth
746 }
747 }
748 pf, status, err := readPropfind(r.Body)
749 if err != nil {
750 return status, err
751 }
752
753 mw := multistatusWriter{w: w}
754
755 walkFn := func(reqPath string, info model.Obj, err error) error {
756 if err != nil {
757 return err
758 }
759 var pstats []Propstat
760 if pf.Propname != nil {
761 pnames, err := propnames(ctx, h.LockSystem, info)
762 if err != nil {
763 return err
764 }
765 pstat := Propstat{Status: http.StatusOK}
766 for _, xmlname := range pnames {
767 pstat.Props = append(pstat.Props, Property{XMLName: xmlname})
768 }
769 pstats = append(pstats, pstat)
770 } else if pf.Allprop != nil {

Callers 1

ServeHTTPMethod · 0.95

Calls 15

stripPrefixMethod · 0.95
writeMethod · 0.95
closeMethod · 0.95
GetNearestMetaFunction · 0.92
CanAccessFunction · 0.92
GetFunction · 0.92
IsNotFoundErrorFunction · 0.92
parseDepthFunction · 0.85
readPropfindFunction · 0.85
propnamesFunction · 0.85
allpropFunction · 0.85
makePropstatResponseFunction · 0.85

Tested by

no test coverage detected