diff --git a/internal/server/handlers.go b/internal/server/handlers.go index e9d5944e..a5207e84 100644 --- a/internal/server/handlers.go +++ b/internal/server/handlers.go @@ -10,10 +10,14 @@ import ( "github.com/githubnext/gh-aw-mcpg/internal/logger" ) +var logHandlers = logger.New("server:handlers") + // handleOAuthDiscovery returns a handler for OAuth discovery endpoint // Returns 404 since the gateway doesn't use OAuth func handleOAuthDiscovery() http.Handler { + logHandlers.Print("Creating OAuth discovery handler") return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + logHandlers.Printf("OAuth discovery request: remote=%s, method=%s, path=%s", r.RemoteAddr, r.Method, r.URL.Path) log.Printf("[%s] %s %s - OAuth discovery (not supported)", r.RemoteAddr, r.Method, r.URL.Path) http.NotFound(w, r) }) @@ -21,18 +25,22 @@ func handleOAuthDiscovery() http.Handler { // handleClose returns a handler for graceful shutdown endpoint (spec 5.1.3) func handleClose(unifiedServer *UnifiedServer) http.Handler { + logHandlers.Print("Creating close handler") return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + logHandlers.Printf("Close request received: remote=%s, method=%s, path=%s", r.RemoteAddr, r.Method, r.URL.Path) log.Printf("[%s] %s %s", r.RemoteAddr, r.Method, r.URL.Path) logger.LogInfo("shutdown", "Close endpoint called, remote=%s", r.RemoteAddr) // Only accept POST requests if r.Method != http.MethodPost { + logHandlers.Printf("Close request rejected: invalid method=%s", r.Method) http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) return } // Check if already closed (idempotency - spec 5.1.3) if unifiedServer.IsShutdown() { + logHandlers.Print("Gateway already shutdown, returning 410 Gone") logger.LogWarn("shutdown", "Close endpoint called but gateway already closed, remote=%s", r.RemoteAddr) w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusGone) // 410 Gone @@ -43,7 +51,9 @@ func handleClose(unifiedServer *UnifiedServer) http.Handler { } // Initiate shutdown and get server count + logHandlers.Print("Initiating gateway shutdown") serversTerminated := unifiedServer.InitiateShutdown() + logHandlers.Printf("Shutdown completed: servers_terminated=%d", serversTerminated) // Return success response (spec 5.1.3) w.Header().Set("Content-Type", "application/json")