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

Function decodeResponse

internal/wsrelay/http.go:193–223  ·  view source on GitHub ↗
(payload map[string]any)

Source from the content-addressed store, hash-verified

191}
192
193func decodeResponse(payload map[string]any) *HTTPResponse {
194 if payload == nil {
195 return &HTTPResponse{Status: http.StatusBadGateway, Headers: make(http.Header)}
196 }
197 resp := &HTTPResponse{Status: http.StatusOK, Headers: make(http.Header)}
198 if status, ok := payload["status"].(float64); ok {
199 resp.Status = int(status)
200 }
201 if headers, ok := payload["headers"].(map[string]any); ok {
202 for key, raw := range headers {
203 switch v := raw.(type) {
204 case []any:
205 for _, item := range v {
206 if str, ok := item.(string); ok {
207 resp.Headers.Add(key, str)
208 }
209 }
210 case []string:
211 for _, str := range v {
212 resp.Headers.Add(key, str)
213 }
214 case string:
215 resp.Headers.Set(key, v)
216 }
217 }
218 }
219 if body, ok := payload["body"].(string); ok {
220 resp.Body = []byte(body)
221 }
222 return resp
223}
224
225func decodeChunk(payload map[string]any) []byte {
226 if payload == nil {

Callers 2

NonStreamMethod · 0.85
StreamMethod · 0.85

Calls 1

SetMethod · 0.45

Tested by

no test coverage detected