Commit ad9eb390 authored by Nigel Tao's avatar Nigel Tao

webdav: delete the PropSystem and MemPS types.

Change-Id: I569993723942f71599411a25ff31e97c1bc8875c
Reviewed-on: https://go-review.googlesource.com/10305Reviewed-by: 's avatarRobert Stepanek <robert.stepanek@gmail.com>
Reviewed-by: 's avatarNigel Tao <nigeltao@golang.org>
parent 7212a080
......@@ -32,12 +32,9 @@ var port = flag.Int("port", 9999, "server port")
func main() {
flag.Parse()
log.SetFlags(0)
fs := webdav.NewMemFS()
ls := webdav.NewMemLS()
h := &webdav.Handler{
FileSystem: fs,
LockSystem: ls,
PropSystem: webdav.NewMemPS(fs, ls),
FileSystem: webdav.NewMemFS(),
LockSystem: webdav.NewMemLS(),
Logger: func(r *http.Request, err error) {
litmus := r.Header.Get("X-Litmus")
if len(litmus) > 19 {
......
This diff is collapsed.
......@@ -43,9 +43,9 @@ func TestMemPS(t *testing.T) {
type propOp struct {
op string
name string
propnames []xml.Name
pnames []xml.Name
patches []Proppatch
wantNames []xml.Name
wantPnames []xml.Name
wantPropstats []Propstat
}
......@@ -60,7 +60,7 @@ func TestMemPS(t *testing.T) {
propOp: []propOp{{
op: "propname",
name: "/dir",
wantNames: []xml.Name{
wantPnames: []xml.Name{
xml.Name{Space: "DAV:", Local: "resourcetype"},
xml.Name{Space: "DAV:", Local: "displayname"},
xml.Name{Space: "DAV:", Local: "getcontentlength"},
......@@ -70,7 +70,7 @@ func TestMemPS(t *testing.T) {
}, {
op: "propname",
name: "/file",
wantNames: []xml.Name{
wantPnames: []xml.Name{
xml.Name{Space: "DAV:", Local: "resourcetype"},
xml.Name{Space: "DAV:", Local: "displayname"},
xml.Name{Space: "DAV:", Local: "getcontentlength"},
......@@ -132,7 +132,7 @@ func TestMemPS(t *testing.T) {
}, {
op: "allprop",
name: "/file",
propnames: []xml.Name{
pnames: []xml.Name{
{"DAV:", "resourcetype"},
{"foo", "bar"},
},
......@@ -167,9 +167,9 @@ func TestMemPS(t *testing.T) {
desc: "propfind DAV:resourcetype",
buildfs: []string{"mkdir /dir", "touch /file"},
propOp: []propOp{{
op: "propfind",
name: "/dir",
propnames: []xml.Name{{"DAV:", "resourcetype"}},
op: "propfind",
name: "/dir",
pnames: []xml.Name{{"DAV:", "resourcetype"}},
wantPropstats: []Propstat{{
Status: http.StatusOK,
Props: []Property{{
......@@ -178,9 +178,9 @@ func TestMemPS(t *testing.T) {
}},
}},
}, {
op: "propfind",
name: "/file",
propnames: []xml.Name{{"DAV:", "resourcetype"}},
op: "propfind",
name: "/file",
pnames: []xml.Name{{"DAV:", "resourcetype"}},
wantPropstats: []Propstat{{
Status: http.StatusOK,
Props: []Property{{
......@@ -193,9 +193,9 @@ func TestMemPS(t *testing.T) {
desc: "propfind unsupported DAV properties",
buildfs: []string{"mkdir /dir"},
propOp: []propOp{{
op: "propfind",
name: "/dir",
propnames: []xml.Name{{"DAV:", "getcontentlanguage"}},
op: "propfind",
name: "/dir",
pnames: []xml.Name{{"DAV:", "getcontentlanguage"}},
wantPropstats: []Propstat{{
Status: http.StatusNotFound,
Props: []Property{{
......@@ -203,9 +203,9 @@ func TestMemPS(t *testing.T) {
}},
}},
}, {
op: "propfind",
name: "/dir",
propnames: []xml.Name{{"DAV:", "creationdate"}},
op: "propfind",
name: "/dir",
pnames: []xml.Name{{"DAV:", "creationdate"}},
wantPropstats: []Propstat{{
Status: http.StatusNotFound,
Props: []Property{{
......@@ -217,9 +217,9 @@ func TestMemPS(t *testing.T) {
desc: "propfind getetag for files but not for directories",
buildfs: []string{"mkdir /dir", "touch /file"},
propOp: []propOp{{
op: "propfind",
name: "/dir",
propnames: []xml.Name{{"DAV:", "getetag"}},
op: "propfind",
name: "/dir",
pnames: []xml.Name{{"DAV:", "getetag"}},
wantPropstats: []Propstat{{
Status: http.StatusNotFound,
Props: []Property{{
......@@ -227,9 +227,9 @@ func TestMemPS(t *testing.T) {
}},
}},
}, {
op: "propfind",
name: "/file",
propnames: []xml.Name{{"DAV:", "getetag"}},
op: "propfind",
name: "/file",
pnames: []xml.Name{{"DAV:", "getetag"}},
wantPropstats: []Propstat{{
Status: http.StatusOK,
Props: []Property{{
......@@ -291,9 +291,9 @@ func TestMemPS(t *testing.T) {
}},
}},
}, {
op: "propfind",
name: "/dir",
propnames: []xml.Name{{Space: "foo", Local: "bar"}},
op: "propfind",
name: "/dir",
pnames: []xml.Name{{Space: "foo", Local: "bar"}},
wantPropstats: []Propstat{{
Status: http.StatusOK,
Props: []Property{{
......@@ -332,9 +332,9 @@ func TestMemPS(t *testing.T) {
}},
}},
}, {
op: "propfind",
name: "/dir",
propnames: []xml.Name{{Space: "foo", Local: "bar"}},
op: "propfind",
name: "/dir",
pnames: []xml.Name{{Space: "foo", Local: "bar"}},
wantPropstats: []Propstat{{
Status: http.StatusNotFound,
Props: []Property{{
......@@ -368,7 +368,7 @@ func TestMemPS(t *testing.T) {
}, {
op: "propfind",
name: "/dir",
propnames: []xml.Name{
pnames: []xml.Name{
{Space: "foo", Local: "bar"},
{Space: "spam", Local: "ham"},
},
......@@ -400,7 +400,7 @@ func TestMemPS(t *testing.T) {
}, {
op: "propfind",
name: "/dir",
propnames: []xml.Name{
pnames: []xml.Name{
{Space: "foo", Local: "bar"},
{Space: "spam", Local: "ham"},
},
......@@ -438,7 +438,7 @@ func TestMemPS(t *testing.T) {
}, {
op: "propname",
name: "/file",
wantNames: []xml.Name{
wantPnames: []xml.Name{
xml.Name{Space: "DAV:", Local: "resourcetype"},
xml.Name{Space: "DAV:", Local: "displayname"},
xml.Name{Space: "DAV:", Local: "getcontentlength"},
......@@ -471,9 +471,9 @@ func TestMemPS(t *testing.T) {
desc: "bad: propfind unknown property",
buildfs: []string{"mkdir /dir"},
propOp: []propOp{{
op: "propfind",
name: "/dir",
propnames: []xml.Name{{"foo:", "bar"}},
op: "propfind",
name: "/dir",
pnames: []xml.Name{{"foo:", "bar"}},
wantPropstats: []Propstat{{
Status: http.StatusNotFound,
Props: []Property{{
......@@ -492,7 +492,6 @@ func TestMemPS(t *testing.T) {
fs = noDeadPropsFS{fs}
}
ls := NewMemLS()
ps := NewMemPS(fs, ls)
for _, op := range tc.propOp {
desc := fmt.Sprintf("%s: %s %s", tc.desc, op.op, op.name)
if err = calcProps(op.name, fs, op.wantPropstats); err != nil {
......@@ -503,23 +502,23 @@ func TestMemPS(t *testing.T) {
var propstats []Propstat
switch op.op {
case "propname":
names, err := ps.Propnames(op.name)
pnames, err := propnames(fs, ls, op.name)
if err != nil {
t.Errorf("%s: got error %v, want nil", desc, err)
continue
}
sort.Sort(byXMLName(names))
sort.Sort(byXMLName(op.wantNames))
if !reflect.DeepEqual(names, op.wantNames) {
t.Errorf("%s: names\ngot %q\nwant %q", desc, names, op.wantNames)
sort.Sort(byXMLName(pnames))
sort.Sort(byXMLName(op.wantPnames))
if !reflect.DeepEqual(pnames, op.wantPnames) {
t.Errorf("%s: pnames\ngot %q\nwant %q", desc, pnames, op.wantPnames)
}
continue
case "allprop":
propstats, err = ps.Allprop(op.name, op.propnames)
propstats, err = allprop(fs, ls, op.name, op.pnames)
case "propfind":
propstats, err = ps.Find(op.name, op.propnames)
propstats, err = props(fs, ls, op.name, op.pnames)
case "proppatch":
propstats, err = ps.Patch(op.name, op.patches)
propstats, err = patch(fs, ls, op.name, op.patches)
default:
t.Fatalf("%s: %s not implemented", desc, op.op)
}
......
......@@ -5,8 +5,6 @@
// Package webdav etc etc TODO.
package webdav // import "golang.org/x/net/webdav"
// TODO: ETag, properties.
import (
"encoding/xml"
"errors"
......@@ -45,8 +43,6 @@ type Handler struct {
FileSystem FileSystem
// LockSystem is the lock management system.
LockSystem LockSystem
// PropSystem is the property management system.
PropSystem PropSystem
// Logger is an optional error logger. If non-nil, it will be called
// for all HTTP requests.
Logger func(*http.Request, error)
......@@ -58,8 +54,6 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
status, err = http.StatusInternalServerError, errNoFileSystem
} else if h.LockSystem == nil {
status, err = http.StatusInternalServerError, errNoLockSystem
} else if h.PropSystem == nil {
status, err = http.StatusInternalServerError, errNoPropSystem
} else {
switch r.Method {
case "OPTIONS":
......@@ -209,7 +203,7 @@ func (h *Handler) handleGetHeadPost(w http.ResponseWriter, r *http.Request) (sta
if err != nil {
return http.StatusNotFound, err
}
pstats, err := h.PropSystem.Find(r.URL.Path, []xml.Name{
pstats, err := props(h.FileSystem, h.LockSystem, r.URL.Path, []xml.Name{
{Space: "DAV:", Local: "getetag"},
{Space: "DAV:", Local: "getcontenttype"},
})
......@@ -264,7 +258,7 @@ func (h *Handler) handlePut(w http.ResponseWriter, r *http.Request) (status int,
if closeErr != nil {
return http.StatusMethodNotAllowed, closeErr
}
pstats, err := h.PropSystem.Find(r.URL.Path, []xml.Name{
pstats, err := props(h.FileSystem, h.LockSystem, r.URL.Path, []xml.Name{
{Space: "DAV:", Local: "getetag"},
})
if err != nil {
......@@ -502,19 +496,19 @@ func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) (status
}
var pstats []Propstat
if pf.Propname != nil {
propnames, err := h.PropSystem.Propnames(path)
pnames, err := propnames(h.FileSystem, h.LockSystem, path)
if err != nil {
return err
}
pstat := Propstat{Status: http.StatusOK}
for _, xmlname := range propnames {
for _, xmlname := range pnames {
pstat.Props = append(pstat.Props, Property{XMLName: xmlname})
}
pstats = append(pstats, pstat)
} else if pf.Allprop != nil {
pstats, err = h.PropSystem.Allprop(path, pf.Prop)
pstats, err = allprop(h.FileSystem, h.LockSystem, path, pf.Prop)
} else {
pstats, err = h.PropSystem.Find(path, pf.Prop)
pstats, err = props(h.FileSystem, h.LockSystem, path, pf.Prop)
}
if err != nil {
return err
......@@ -550,7 +544,7 @@ func (h *Handler) handleProppatch(w http.ResponseWriter, r *http.Request) (statu
if err != nil {
return status, err
}
pstats, err := h.PropSystem.Patch(r.URL.Path, patches)
pstats, err := patch(h.FileSystem, h.LockSystem, r.URL.Path, patches)
if err != nil {
return http.StatusInternalServerError, err
}
......@@ -671,7 +665,6 @@ var (
errInvalidTimeout = errors.New("webdav: invalid timeout")
errNoFileSystem = errors.New("webdav: no file system")
errNoLockSystem = errors.New("webdav: no lock system")
errNoPropSystem = errors.New("webdav: no property system")
errNotADirectory = errors.New("webdav: not a directory")
errRecursionTooDeep = errors.New("webdav: recursion too deep")
errUnsupportedLockInfo = errors.New("webdav: unsupported lock info")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment