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.

84 lines
3.0 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. if _, ok := r.URL.Query()["tagging"]; ok {
  27. fs.DeleteTaggingHandler(w,r)
  28. } else {
  29. fs.DeleteHandler(w, r)
  30. }
  31. stats.FilerRequestHistogram.WithLabelValues("delete").Observe(time.Since(start).Seconds())
  32. case "PUT":
  33. stats.FilerRequestCounter.WithLabelValues("put").Inc()
  34. if _, ok := r.URL.Query()["tagging"]; ok {
  35. fs.PutTaggingHandler(w,r)
  36. } else {
  37. fs.PostHandler(w, r)
  38. }
  39. stats.FilerRequestHistogram.WithLabelValues("put").Observe(time.Since(start).Seconds())
  40. case "POST":
  41. stats.FilerRequestCounter.WithLabelValues("post").Inc()
  42. fs.PostHandler(w, r)
  43. stats.FilerRequestHistogram.WithLabelValues("post").Observe(time.Since(start).Seconds())
  44. case "OPTIONS":
  45. stats.FilerRequestCounter.WithLabelValues("options").Inc()
  46. OptionsHandler(w, r, false)
  47. stats.FilerRequestHistogram.WithLabelValues("head").Observe(time.Since(start).Seconds())
  48. }
  49. }
  50. func (fs *FilerServer) readonlyFilerHandler(w http.ResponseWriter, r *http.Request) {
  51. w.Header().Set("Server", "SeaweedFS Filer "+util.VERSION)
  52. if r.Header.Get("Origin") != "" {
  53. w.Header().Set("Access-Control-Allow-Origin", "*")
  54. w.Header().Set("Access-Control-Allow-Credentials", "true")
  55. }
  56. start := time.Now()
  57. switch r.Method {
  58. case "GET":
  59. stats.FilerRequestCounter.WithLabelValues("get").Inc()
  60. fs.GetOrHeadHandler(w, r, true)
  61. stats.FilerRequestHistogram.WithLabelValues("get").Observe(time.Since(start).Seconds())
  62. case "HEAD":
  63. stats.FilerRequestCounter.WithLabelValues("head").Inc()
  64. fs.GetOrHeadHandler(w, r, false)
  65. stats.FilerRequestHistogram.WithLabelValues("head").Observe(time.Since(start).Seconds())
  66. case "OPTIONS":
  67. stats.FilerRequestCounter.WithLabelValues("options").Inc()
  68. OptionsHandler(w, r, true)
  69. stats.FilerRequestHistogram.WithLabelValues("head").Observe(time.Since(start).Seconds())
  70. }
  71. }
  72. func OptionsHandler(w http.ResponseWriter, r *http.Request, isReadOnly bool) {
  73. if isReadOnly {
  74. w.Header().Add("Access-Control-Allow-Methods", "GET, OPTIONS")
  75. } else {
  76. w.Header().Add("Access-Control-Allow-Methods", "PUT, POST, GET, DELETE, OPTIONS")
  77. }
  78. w.Header().Add("Access-Control-Allow-Headers", "*")
  79. }