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