MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / withMiddleware

Method withMiddleware

internal/sidecar/server.go:102–117  ·  view source on GitHub ↗
(next http.Handler)

Source from the content-addressed store, hash-verified

100}
101
102func (s *Server) withMiddleware(next http.Handler) http.Handler {
103 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
104 w.Header().Set("Access-Control-Allow-Origin", "*")
105 w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type")
106 w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS")
107 if r.Method == http.MethodOptions {
108 w.WriteHeader(http.StatusNoContent)
109 return
110 }
111 if s.token != "" && r.Header.Get("Authorization") != "Bearer "+s.token {
112 writeError(w, http.StatusUnauthorized, "unauthorized")
113 return
114 }
115 next.ServeHTTP(w, r)
116 })
117}
118
119func (s *Server) handleVersion(w http.ResponseWriter, r *http.Request) {
120 if r.Method != http.MethodGet {

Callers 1

HandlerMethod · 0.95

Calls 4

writeErrorFunction · 0.85
SetMethod · 0.65
HeaderMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected