MCPcopy Create free account
hub / github.com/asternic/wuzapi / executeHTTPHandler

Method executeHTTPHandler

stdio.go:477–504  ·  view source on GitHub ↗

executeHTTPHandler wraps the existing HTTP handler and adapts it for stdio

(req *jsonRpcRequest, httpMethod, httpPath string)

Source from the content-addressed store, hash-verified

475 httpMethod = "DELETE"
476 httpPath = "/webhook"
477
478 default:
479 ss.sendError(req.ID, 404, fmt.Sprintf("unknown method: %s", req.Method))
480 return
481 }
482 ss.executeHTTPHandler(req, httpMethod, httpPath)
483}
484
485// executeHTTPHandler wraps the existing HTTP handler and adapts it for stdio
486func (ss *stdioServer) executeHTTPHandler(req *jsonRpcRequest, httpMethod, httpPath string) {
487 // Create a mock HTTP request
488 var body io.Reader
489 if req.Params != nil && len(req.Params) > 0 {
490 jsonParams, err := json.Marshal(req.Params)
491 if err != nil {
492 ss.sendError(req.ID, 400, fmt.Sprintf("invalid params: %v", err))
493 return
494 }
495 body = bytes.NewReader(jsonParams)
496 }
497
498 httpReq := httptest.NewRequest(httpMethod, httpPath, body)
499 httpReq.Header.Set("Content-Type", "application/json")
500
501 // Set user token header (for user authentication)
502 if token, ok := req.Params["token"].(string); ok {
503 httpReq.Header.Set("token", token)
504 }
505 // Set admin token header (for admin authentication)
506 if adminToken, ok := req.Params["adminToken"].(string); ok {
507 httpReq.Header.Set("Authorization", adminToken)

Callers 1

routeRequestMethod · 0.95

Calls 2

sendErrorMethod · 0.95
convertHTTPResponseMethod · 0.95

Tested by

no test coverage detected