litmus_test_server.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.
  4. // +build ignore
  5. /*
  6. This program is a server for the WebDAV 'litmus' compliance test at
  7. http://www.webdav.org/neon/litmus/
  8. To run the test:
  9. go run litmus_test_server.go
  10. and separately, from the downloaded litmus-xxx directory:
  11. make URL=http://localhost:9999/ check
  12. */
  13. package main
  14. import (
  15. "flag"
  16. "fmt"
  17. "log"
  18. "net/http"
  19. "net/url"
  20. "golang.org/x/net/webdav"
  21. )
  22. var port = flag.Int("port", 9999, "server port")
  23. func main() {
  24. flag.Parse()
  25. http.Handle("/", &webdav.Handler{
  26. FileSystem: webdav.NewMemFS(),
  27. LockSystem: webdav.NewMemLS(),
  28. Logger: func(r *http.Request, err error) {
  29. switch r.Method {
  30. case "COPY", "MOVE":
  31. dst := ""
  32. if u, err := url.Parse(r.Header.Get("Destination")); err == nil {
  33. dst = u.Path
  34. }
  35. o := r.Header.Get("Overwrite")
  36. log.Printf("%-10s%-25s%-25so=%-2s%v", r.Method, r.URL.Path, dst, o, err)
  37. default:
  38. log.Printf("%-10s%-30s%v", r.Method, r.URL.Path, err)
  39. }
  40. },
  41. })
  42. addr := fmt.Sprintf(":%d", *port)
  43. log.Printf("Serving %v", addr)
  44. log.Fatal(http.ListenAndServe(addr, nil))
  45. }