webdav: improve support for url prefixes
StripPrefix in the webdav package strips prefixes from requests
(including the Destination headers) but cannot handle the paths
in the xml entities responses which are confusing some clients
(e.g. cadaver).
This patch replaces StripPrefix with Prefix in the Handler to
handle prefixes both in the requests and in the xml entities
responses.
Change-Id: I67062e30337b2ae422c82a2f927454f5a8a00e34
Reviewed-on: https://go-review.googlesource.com/13857
Reviewed-by: Nigel Tao <nigeltao@golang.org>
diff --git a/webdav/webdav_test.go b/webdav/webdav_test.go
index c422860..45b4055 100644
--- a/webdav/webdav_test.go
+++ b/webdav/webdav_test.go
@@ -15,13 +15,8 @@
"testing"
)
-// TestStripPrefix tests the StripPrefix function. We can't test the
-// StripPrefix function with the litmus test, even though all of the litmus
-// test paths start with "/litmus/", because one of the first things that the
-// litmus test does is "MKCOL /litmus/". That request succeeds without a
-// StripPrefix, but fails with a StripPrefix because you cannot MKCOL the root
-// directory of a FileSystem.
-func TestStripPrefix(t *testing.T) {
+// TODO: add tests to check XML responses with the expected prefix path
+func TestPrefix(t *testing.T) {
const dst, blah = "Destination", "blah blah blah"
do := func(method, urlStr string, body io.Reader, wantStatusCode int, headers ...string) error {
@@ -52,14 +47,13 @@
}
for _, prefix := range prefixes {
fs := NewMemFS()
- h := http.Handler(&Handler{
+ h := &Handler{
FileSystem: fs,
LockSystem: NewMemLS(),
- })
+ }
mux := http.NewServeMux()
if prefix != "/" {
- // Note that this is webdav.StripPrefix, not http.StripPrefix.
- h = StripPrefix(prefix, h)
+ h.Prefix = prefix
}
mux.Handle(prefix, h)
srv := httptest.NewServer(mux)