MCPcopy Create free account
hub / github.com/dank/rlapi / handleWebSocket

Method handleWebSocket

psynetrpc_test.go:63–106  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

61}
62
63func (m *MockWSServer) handleWebSocket(w http.ResponseWriter, r *http.Request) {
64 conn, err := m.upgrader.Upgrade(w, r, nil)
65 if err != nil {
66 return
67 }
68 defer conn.Close()
69
70 for {
71 messageType, message, err := conn.ReadMessage()
72 if err != nil {
73 break
74 }
75
76 if messageType == websocket.TextMessage {
77 msg := string(message)
78 m.messages = append(m.messages, msg)
79
80 // Handle ping messages
81 if strings.Contains(msg, "PsyPing:") && m.pongResponse && !m.dropPongs {
82 pongMessage := "PsyPong: \r\n\r\n"
83 conn.WriteMessage(websocket.TextMessage, []byte(pongMessage))
84 }
85
86 // Parse PsyRequestID from the message
87 if strings.Contains(msg, "PsyRequestID:") {
88 lines := strings.Split(msg, "\r\n")
89 for _, line := range lines {
90 if strings.HasPrefix(line, "PsyRequestID:") {
91 requestID := strings.TrimSpace(strings.TrimPrefix(line, "PsyRequestID:"))
92
93 // Send predefined response if available
94 if response, exists := m.responses[requestID]; exists {
95 // Format as PsyNet message with headers and the Result as JSON payload
96 psyNetResponse := fmt.Sprintf("PsyTime: %d\r\nPsySig: test_sig\r\nPsyResponseID: %s\r\n\r\n%s",
97 time.Now().Unix(), requestID, string(response.Result))
98 conn.WriteMessage(websocket.TextMessage, []byte(psyNetResponse))
99 }
100 break
101 }
102 }
103 }
104 }
105 }
106}
107
108func TestPsyNetRPC_SendRequestSync(t *testing.T) {
109 // Setup mock server

Callers

nothing calls this directly

Calls 1

CloseMethod · 0.45

Tested by

no test coverage detected