1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
8 This program is a server for the WebDAV 'litmus' compliance test at
9 http://www.webdav.org/neon/litmus/
12 go run litmus_test_server.go
14 and separately, from the downloaded litmus-xxx directory:
16 make URL=http://localhost:9999/ check
27 "golang.org/x/net/webdav"
30 var port = flag.Int("port", 9999, "server port")
36 FileSystem: webdav.NewMemFS(),
37 LockSystem: webdav.NewMemLS(),
38 Logger: func(r *http.Request, err error) {
39 litmus := r.Header.Get("X-Litmus")
41 litmus = litmus[:16] + "..."
47 if u, err := url.Parse(r.Header.Get("Destination")); err == nil {
50 o := r.Header.Get("Overwrite")
51 log.Printf("%-20s%-10s%-30s%-30so=%-2s%v", litmus, r.Method, r.URL.Path, dst, o, err)
53 log.Printf("%-20s%-10s%-30s%v", litmus, r.Method, r.URL.Path, err)
58 // The next line would normally be:
59 // http.Handle("/", h)
60 // but we wrap that HTTP handler h to cater for a special case.
62 // The propfind_invalid2 litmus test case expects an empty namespace prefix
63 // declaration to be an error. The FAQ in the webdav litmus test says:
65 // "What does the "propfind_invalid2" test check for?...
67 // If a request was sent with an XML body which included an empty namespace
68 // prefix declaration (xmlns:ns1=""), then the server must reject that with
69 // a "400 Bad Request" response, as it is invalid according to the XML
70 // Namespace specification."
72 // On the other hand, the Go standard library's encoding/xml package
73 // accepts an empty xmlns namespace, as per the discussion at
74 // https://github.com/golang/go/issues/8068
76 // Empty namespaces seem disallowed in the second (2006) edition of the XML
77 // standard, but allowed in a later edition. The grammar differs between
78 // http://www.w3.org/TR/2006/REC-xml-names-20060816/#ns-decl and
79 // http://www.w3.org/TR/REC-xml-names/#dt-prefix
81 // Thus, we assume that the propfind_invalid2 test is obsolete, and
82 // hard-code the 400 Bad Request response that the test expects.
83 http.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
84 if r.Header.Get("X-Litmus") == "props: 3 (propfind_invalid2)" {
85 http.Error(w, "400 Bad Request", http.StatusBadRequest)
91 addr := fmt.Sprintf(":%d", *port)
92 log.Printf("Serving %v", addr)
93 log.Fatal(http.ListenAndServe(addr, nil))