litmus_test_server.go 1.4 KB

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