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.

91 lines
3.3 KiB

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