You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.8 KiB

4 years ago
6 years ago
4 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
4 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
4 years ago
  1. package weed_server
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/util"
  4. "net/http"
  5. "time"
  6. "github.com/chrislusf/seaweedfs/weed/stats"
  7. )
  8. func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) {
  9. w.Header().Set("Server", "SeaweedFS Filer "+util.VERSION)
  10. if r.Header.Get("Origin") != "" {
  11. w.Header().Set("Access-Control-Allow-Origin", "*")
  12. w.Header().Set("Access-Control-Allow-Credentials", "true")
  13. }
  14. start := time.Now()
  15. switch r.Method {
  16. case "GET":
  17. stats.FilerRequestCounter.WithLabelValues("get").Inc()
  18. fs.GetOrHeadHandler(w, r, true)
  19. stats.FilerRequestHistogram.WithLabelValues("get").Observe(time.Since(start).Seconds())
  20. case "HEAD":
  21. stats.FilerRequestCounter.WithLabelValues("head").Inc()
  22. fs.GetOrHeadHandler(w, r, false)
  23. stats.FilerRequestHistogram.WithLabelValues("head").Observe(time.Since(start).Seconds())
  24. case "DELETE":
  25. stats.FilerRequestCounter.WithLabelValues("delete").Inc()
  26. fs.DeleteHandler(w, r)
  27. stats.FilerRequestHistogram.WithLabelValues("delete").Observe(time.Since(start).Seconds())
  28. case "PUT":
  29. stats.FilerRequestCounter.WithLabelValues("put").Inc()
  30. fs.PostHandler(w, r)
  31. stats.FilerRequestHistogram.WithLabelValues("put").Observe(time.Since(start).Seconds())
  32. case "POST":
  33. stats.FilerRequestCounter.WithLabelValues("post").Inc()
  34. fs.PostHandler(w, r)
  35. stats.FilerRequestHistogram.WithLabelValues("post").Observe(time.Since(start).Seconds())
  36. case "OPTIONS":
  37. stats.FilerRequestCounter.WithLabelValues("options").Inc()
  38. OptionsHandler(w, r, false)
  39. stats.FilerRequestHistogram.WithLabelValues("head").Observe(time.Since(start).Seconds())
  40. }
  41. }
  42. func (fs *FilerServer) readonlyFilerHandler(w http.ResponseWriter, r *http.Request) {
  43. w.Header().Set("Server", "SeaweedFS Filer "+util.VERSION)
  44. if r.Header.Get("Origin") != "" {
  45. w.Header().Set("Access-Control-Allow-Origin", "*")
  46. w.Header().Set("Access-Control-Allow-Credentials", "true")
  47. }
  48. start := time.Now()
  49. switch r.Method {
  50. case "GET":
  51. stats.FilerRequestCounter.WithLabelValues("get").Inc()
  52. fs.GetOrHeadHandler(w, r, true)
  53. stats.FilerRequestHistogram.WithLabelValues("get").Observe(time.Since(start).Seconds())
  54. case "HEAD":
  55. stats.FilerRequestCounter.WithLabelValues("head").Inc()
  56. fs.GetOrHeadHandler(w, r, false)
  57. stats.FilerRequestHistogram.WithLabelValues("head").Observe(time.Since(start).Seconds())
  58. case "OPTIONS":
  59. stats.FilerRequestCounter.WithLabelValues("options").Inc()
  60. OptionsHandler(w, r, true)
  61. stats.FilerRequestHistogram.WithLabelValues("head").Observe(time.Since(start).Seconds())
  62. }
  63. }
  64. func OptionsHandler(w http.ResponseWriter, r *http.Request, isReadOnly bool) {
  65. if isReadOnly {
  66. w.Header().Add("Access-Control-Allow-Methods", "GET, OPTIONS")
  67. } else {
  68. w.Header().Add("Access-Control-Allow-Methods", "PUT, POST, GET, DELETE, OPTIONS")
  69. }
  70. w.Header().Add("Access-Control-Allow-Headers", "*")
  71. }