Commit db8e4de5 authored by Federico Simoncelli's avatar Federico Simoncelli Committed by Nigel Tao

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/13857Reviewed-by: 's avatarNigel Tao <nigeltao@golang.org>
parent ea47fc70
This diff is collapsed.
......@@ -15,13 +15,8 @@ import (
"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 @@ func TestStripPrefix(t *testing.T) {
}
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)
......
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