litmus_test_server.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. log.SetFlags(0)
  26. http.Handle("/", &webdav.Handler{
  27. FileSystem: webdav.NewMemFS(),
  28. LockSystem: webdav.NewMemLS(),
  29. Logger: func(r *http.Request, err error) {
  30. litmus := r.Header.Get("X-Litmus")
  31. if len(litmus) > 19 {
  32. litmus = litmus[:16] + "..."
  33. }
  34. switch r.Method {
  35. case "COPY", "MOVE":
  36. dst := ""
  37. if u, err := url.Parse(r.Header.Get("Destination")); err == nil {
  38. dst = u.Path
  39. }
  40. o := r.Header.Get("Overwrite")
  41. log.Printf("%-20s%-10s%-30s%-30so=%-2s%v", litmus, r.Method, r.URL.Path, dst, o, err)
  42. default:
  43. log.Printf("%-20s%-10s%-30s%v", litmus, r.Method, r.URL.Path, err)
  44. }
  45. },
  46. })
  47. addr := fmt.Sprintf(":%d", *port)
  48. log.Printf("Serving %v", addr)
  49. log.Fatal(http.ListenAndServe(addr, nil))
  50. }