(allowedMethods allowedMethods, next http.Handler)
| 33 | } |
| 34 | |
| 35 | func allowedMethodsHandler(allowedMethods allowedMethods, next http.Handler) http.Handler { |
| 36 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 37 | if _, ok := allowedMethods[r.Method]; !ok { |
| 38 | x.AddCorsHeaders(w) |
| 39 | if r.Method == http.MethodOptions { |
| 40 | return |
| 41 | } |
| 42 | x.SetStatus(w, x.ErrorInvalidMethod, "Invalid method") |
| 43 | w.WriteHeader(http.StatusMethodNotAllowed) |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | next.ServeHTTP(w, r) |
| 48 | }) |
| 49 | } |
| 50 | |
| 51 | // adminAuthHandler does some standard checks for admin endpoints. |
| 52 | // It returns if something is wrong. Otherwise, it lets the given handler serve the request. |
no test coverage detected