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

Method handleRender

tsunami/engine/serverhandlers.go:101–175  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

99}
100
101func (h *httpHandlers) handleRender(w http.ResponseWriter, r *http.Request) {
102 defer func() {
103 panicErr := util.PanicHandler("handleRender", recover())
104 if panicErr != nil {
105 http.Error(w, fmt.Sprintf("internal server error: %v", panicErr), http.StatusInternalServerError)
106 }
107 }()
108
109 setNoCacheHeaders(w)
110
111 if r.Method != http.MethodPost {
112 http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
113 return
114 }
115
116 body, err := io.ReadAll(r.Body)
117 if err != nil {
118 http.Error(w, fmt.Sprintf("failed to read request body: %v", err), http.StatusBadRequest)
119 return
120 }
121
122 var feUpdate rpctypes.VDomFrontendUpdate
123 if err := json.Unmarshal(body, &feUpdate); err != nil {
124 http.Error(w, fmt.Sprintf("failed to parse JSON: %v", err), http.StatusBadRequest)
125 return
126 }
127
128 if feUpdate.ForceTakeover {
129 h.Client.clientTakeover(feUpdate.ClientId)
130 }
131
132 if err := h.Client.checkClientId(feUpdate.ClientId); err != nil {
133 http.Error(w, fmt.Sprintf("client id error: %v", err), http.StatusBadRequest)
134 return
135 }
136
137 startTime := time.Now()
138 update, err := h.processFrontendUpdate(&feUpdate)
139 duration := time.Since(startTime)
140
141 if err != nil {
142 http.Error(w, fmt.Sprintf("render error: %v", err), http.StatusInternalServerError)
143 return
144 }
145 if update == nil {
146 w.WriteHeader(http.StatusOK)
147 if os.Getenv("TSUNAMI_DEBUG") != "" {
148 log.Printf("render %4s %4dms %4dk %s", "none", duration.Milliseconds(), 0, feUpdate.Reason)
149 }
150 return
151 }
152
153 w.Header().Set("Content-Type", "application/json")
154
155 // Encode to bytes first to calculate size
156 responseBytes, err := json.Marshal(update)
157 if err != nil {
158 log.Printf("failed to encode response: %v", err)

Callers

nothing calls this directly

Calls 11

processFrontendUpdateMethod · 0.95
PanicHandlerFunction · 0.92
setNoCacheHeadersFunction · 0.85
clientTakeoverMethod · 0.80
checkClientIdMethod · 0.80
WriteMethod · 0.65
ErrorMethod · 0.45
ReadAllMethod · 0.45
WriteHeaderMethod · 0.45
SetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected