MCPcopy
hub / github.com/dgraph-io/dgraph / allowedMethodsHandler

Function allowedMethodsHandler

dgraph/cmd/alpha/admin.go:35–49  ·  view source on GitHub ↗
(allowedMethods allowedMethods, next http.Handler)

Source from the content-addressed store, hash-verified

33}
34
35func 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.

Callers 2

getAdminMuxFunction · 0.85
setupServerFunction · 0.85

Calls 4

AddCorsHeadersFunction · 0.92
SetStatusFunction · 0.92
ServeHTTPMethod · 0.80
WriteHeaderMethod · 0.65

Tested by

no test coverage detected