MCPcopy
hub / github.com/wavetermdev/waveterm / handleVDom

Function handleVDom

pkg/web/webvdomproto.go:20–110  ·  view source on GitHub ↗

Add the new handler function

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

18
19// Add the new handler function
20func handleVDom(w http.ResponseWriter, r *http.Request) {
21 // Extract UUID and path from URL
22 pathParts := strings.Split(strings.TrimPrefix(r.URL.Path, "/vdom/"), "/")
23 if len(pathParts) < 1 {
24 http.Error(w, "Invalid VDOM URL format", http.StatusBadRequest)
25 return
26 }
27
28 uuid := pathParts[0]
29 // Simple UUID validation
30 if len(uuid) != 36 {
31 http.Error(w, "Invalid UUID format", http.StatusBadRequest)
32 return
33 }
34
35 // Reconstruct the remaining path
36 path := "/" + strings.Join(pathParts[1:], "/")
37 if r.URL.RawQuery != "" {
38 path += "?" + r.URL.RawQuery
39 }
40
41 // Read request body if present
42 var body []byte
43 var err error
44 if r.Body != nil {
45 body, err = io.ReadAll(r.Body)
46 if err != nil {
47 http.Error(w, fmt.Sprintf("Error reading request body: %v", err), http.StatusInternalServerError)
48 return
49 }
50 defer r.Body.Close()
51 }
52
53 // Convert headers to map
54 headers := make(map[string]string)
55 for key, values := range r.Header {
56 if len(values) > 0 {
57 headers[key] = values[0]
58 }
59 }
60
61 // Prepare RPC request data
62 data := wshrpc.VDomUrlRequestData{
63 Method: r.Method,
64 URL: path,
65 Headers: headers,
66 Body: body,
67 }
68
69 // Get RPC client
70 client := wshserver.GetMainRpcClient()
71
72 // Make RPC call with route to specific process
73 route := wshutil.MakeProcRouteId(uuid)
74 respCh := wshclient.VDomUrlRequestCommand(client, data, &wshrpc.RpcOpts{
75 Route: route,
76 })
77

Callers

nothing calls this directly

Calls 10

GetMainRpcClientFunction · 0.92
MakeProcRouteIdFunction · 0.92
VDomUrlRequestCommandFunction · 0.92
CloseMethod · 0.65
WriteMethod · 0.65
ErrorMethod · 0.45
ReadAllMethod · 0.45
WriteHeaderMethod · 0.45
SetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected