|
|
@ -1,6 +1,7 @@ |
|
|
|
package weed_server |
|
|
|
|
|
|
|
import ( |
|
|
|
"context" |
|
|
|
"errors" |
|
|
|
"net/http" |
|
|
|
"os" |
|
|
@ -9,7 +10,9 @@ import ( |
|
|
|
"sync/atomic" |
|
|
|
"time" |
|
|
|
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/filer" |
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog" |
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb" |
|
|
|
"github.com/seaweedfs/seaweedfs/weed/security" |
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util" |
|
|
|
|
|
|
@ -44,7 +47,7 @@ func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
w.Header().Set("Access-Control-Allow-Methods", "PUT, POST, GET, DELETE, OPTIONS") |
|
|
|
} |
|
|
|
|
|
|
|
if r.Method == "OPTIONS" { |
|
|
|
if r.Method == http.MethodOptions { |
|
|
|
OptionsHandler(w, r, false) |
|
|
|
return |
|
|
|
} |
|
|
@ -66,7 +69,7 @@ func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
stats.FilerRequestHistogram.WithLabelValues(r.Method).Observe(time.Since(start).Seconds()) |
|
|
|
}() |
|
|
|
|
|
|
|
isReadHttpCall := r.Method == "GET" || r.Method == "HEAD" |
|
|
|
isReadHttpCall := r.Method == http.MethodGet || r.Method == http.MethodHead |
|
|
|
if !fs.maybeCheckJwtAuthorization(r, !isReadHttpCall) { |
|
|
|
writeJsonError(w, r, http.StatusUnauthorized, errors.New("wrong jwt")) |
|
|
|
return |
|
|
@ -75,17 +78,15 @@ func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
w.Header().Set("Server", "SeaweedFS Filer "+util.VERSION) |
|
|
|
|
|
|
|
switch r.Method { |
|
|
|
case "GET": |
|
|
|
case http.MethodGet, http.MethodHead: |
|
|
|
fs.GetOrHeadHandler(w, r) |
|
|
|
case "HEAD": |
|
|
|
fs.GetOrHeadHandler(w, r) |
|
|
|
case "DELETE": |
|
|
|
case http.MethodDelete: |
|
|
|
if _, ok := r.URL.Query()["tagging"]; ok { |
|
|
|
fs.DeleteTaggingHandler(w, r) |
|
|
|
} else { |
|
|
|
fs.DeleteHandler(w, r) |
|
|
|
} |
|
|
|
case "POST", "PUT": |
|
|
|
case http.MethodPost, http.MethodPut: |
|
|
|
// wait until in flight data is less than the limit
|
|
|
|
contentLength := getContentLength(r) |
|
|
|
fs.inFlightDataLimitCond.L.Lock() |
|
|
@ -102,7 +103,7 @@ func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
fs.inFlightDataLimitCond.Signal() |
|
|
|
}() |
|
|
|
|
|
|
|
if r.Method == "PUT" { |
|
|
|
if r.Method == http.MethodPut { |
|
|
|
if _, ok := r.URL.Query()["tagging"]; ok { |
|
|
|
fs.PutTaggingHandler(w, r) |
|
|
|
} else { |
|
|
@ -111,6 +112,8 @@ func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
} else { // method == "POST"
|
|
|
|
fs.PostHandler(w, r, contentLength) |
|
|
|
} |
|
|
|
default: |
|
|
|
w.WriteHeader(http.StatusMethodNotAllowed) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -149,7 +152,7 @@ func (fs *FilerServer) readonlyFilerHandler(w http.ResponseWriter, r *http.Reque |
|
|
|
stats.FilerRequestHistogram.WithLabelValues(r.Method).Observe(time.Since(start).Seconds()) |
|
|
|
}() |
|
|
|
// We handle OPTIONS first because it never should be authenticated
|
|
|
|
if r.Method == "OPTIONS" { |
|
|
|
if r.Method == http.MethodOptions { |
|
|
|
OptionsHandler(w, r, true) |
|
|
|
return |
|
|
|
} |
|
|
@ -162,10 +165,10 @@ func (fs *FilerServer) readonlyFilerHandler(w http.ResponseWriter, r *http.Reque |
|
|
|
w.Header().Set("Server", "SeaweedFS Filer "+util.VERSION) |
|
|
|
|
|
|
|
switch r.Method { |
|
|
|
case "GET": |
|
|
|
fs.GetOrHeadHandler(w, r) |
|
|
|
case "HEAD": |
|
|
|
case http.MethodGet, http.MethodHead: |
|
|
|
fs.GetOrHeadHandler(w, r) |
|
|
|
default: |
|
|
|
w.WriteHeader(http.StatusMethodNotAllowed) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -220,5 +223,10 @@ func (fs *FilerServer) maybeCheckJwtAuthorization(r *http.Request, isWrite bool) |
|
|
|
|
|
|
|
func (fs *FilerServer) filerHealthzHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
w.Header().Set("Server", "SeaweedFS Filer "+util.VERSION) |
|
|
|
w.WriteHeader(http.StatusOK) |
|
|
|
if _, err := fs.filer.Store.FindEntry(context.Background(), filer.TopicsDir); err != nil && err != filer_pb.ErrNotFound { |
|
|
|
glog.Warningf("filerHealthzHandler FindEntry: %+v", err) |
|
|
|
w.WriteHeader(http.StatusServiceUnavailable) |
|
|
|
} else { |
|
|
|
w.WriteHeader(http.StatusOK) |
|
|
|
} |
|
|
|
} |