| 191 | } |
| 192 | |
| 193 | func 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 | |
| 225 | func decodeChunk(payload map[string]any) []byte { |
| 226 | if payload == nil { |