MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / AttachWebsocketRoute

Method AttachWebsocketRoute

internal/api/server.go:561–594  ·  view source on GitHub ↗

AttachWebsocketRoute registers a websocket upgrade handler on the primary Gin engine. The handler is served as-is without additional middleware beyond the standard stack already configured.

(path string, handler http.Handler)

Source from the content-addressed store, hash-verified

559// AttachWebsocketRoute registers a websocket upgrade handler on the primary Gin engine.
560// The handler is served as-is without additional middleware beyond the standard stack already configured.
561func (s *Server) AttachWebsocketRoute(path string, handler http.Handler) {
562 if s == nil || s.engine == nil || handler == nil {
563 return
564 }
565 trimmed := strings.TrimSpace(path)
566 if trimmed == "" {
567 trimmed = "/v1/ws"
568 }
569 if !strings.HasPrefix(trimmed, "/") {
570 trimmed = "/" + trimmed
571 }
572 s.wsRouteMu.Lock()
573 if _, exists := s.wsRoutes[trimmed]; exists {
574 s.wsRouteMu.Unlock()
575 return
576 }
577 s.wsRoutes[trimmed] = struct{}{}
578 s.wsRouteMu.Unlock()
579
580 authMiddleware := AuthMiddleware(s.accessManager)
581 conditionalAuth := func(c *gin.Context) {
582 if !s.wsAuthEnabled.Load() {
583 c.Next()
584 return
585 }
586 authMiddleware(c)
587 }
588 finalHandler := func(c *gin.Context) {
589 handler.ServeHTTP(c.Writer, c.Request)
590 c.Abort()
591 }
592
593 s.engine.GET(trimmed, conditionalAuth, finalHandler)
594}
595
596func (s *Server) registerManagementRoutes() {
597 if s == nil || s.engine == nil || s.mgmt == nil {

Callers 1

RunMethod · 0.80

Calls 3

AuthMiddlewareFunction · 0.85
NextMethod · 0.80
LoadMethod · 0.65

Tested by

no test coverage detected