Пример #1
0
// http://www.webdav.org/specs/rfc4918.html#METHOD_PROPFIND
func (s *WebDAV) doPropfind(ctx context, w http.ResponseWriter, r *http.Request) {
	// TODO(nmvc): Limit request size.
	req, err := x.ParsePropFind(r.Body)
	if err != nil {
		s.errorHeader(ctx, w, ErrorBadPropfind.WithCause(err))
		return
	}

	files, err := ctx.p.LookupSubtree(ctx.depth)
	if err != nil {
		s.errorHeader(ctx, w, err)
		return
	}
	log.Printf("FOUND %d files", len(files))

	ms := x.NewMultiStatus()
	for _, f := range files {
		var found, missing []x.Any
		for _, pn := range req.PropertyNames {
			v, ok := s.getPropValue(pn, f)
			if ok {
				found = append(found, v)
			} else {
				missing = append(missing, v)
			}
		}
		ms.AddPropStatus(f.GetPath(), found, missing)
	}
	ms.Send(w)
}
Пример #2
0
// http://www.wbdav.org/specs/rfc4918.html#METHOD_DELETE
func (s *WebDAV) doDelete(ctx context, w http.ResponseWriter, r *http.Request) {
	if !s.checkCanWrite(ctx, ctx.p) {
		s.errorHeader(ctx, w, ErrorLocked)
		return
	}

	f, err := ctx.p.Lookup()
	if err != nil {
		s.errorHeader(ctx, w, err)
		return
	}

	if !f.IsDirectory() {
		err = ctx.p.Remove()
		if err != nil {
			s.errorHeader(ctx, w, err)
			return
		}
		return
	}

	errs := ctx.p.RecursiveRemove()
	if len(errs) == 0 {
		w.WriteHeader(http.StatusNoContent)
	} else {
		ms := x.NewMultiStatus()
		for p, e := range errs {
			ms.AddStatus(p, e)
		}
		ms.Send(w)
	}
}