handleModelListResponse processes the model list response and applies filtering based on redirect rules
(c *gin.Context, resp *http.Response, group *models.Group, channelHandler channel.ChannelProxy)
| 26 | |
| 27 | // handleModelListResponse processes the model list response and applies filtering based on redirect rules |
| 28 | func (ps *ProxyServer) handleModelListResponse(c *gin.Context, resp *http.Response, group *models.Group, channelHandler channel.ChannelProxy) { |
| 29 | // Read the upstream response body |
| 30 | bodyBytes, err := io.ReadAll(resp.Body) |
| 31 | if err != nil { |
| 32 | logrus.WithError(err).Error("Failed to read model list response body") |
| 33 | c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to read response"}) |
| 34 | return |
| 35 | } |
| 36 | |
| 37 | // Decompress response data based on Content-Encoding |
| 38 | contentEncoding := resp.Header.Get("Content-Encoding") |
| 39 | decompressed, err := utils.DecompressResponse(contentEncoding, bodyBytes) |
| 40 | if err != nil { |
| 41 | logrus.WithError(err).Warn("Decompression failed, using original data") |
| 42 | decompressed = bodyBytes |
| 43 | } |
| 44 | |
| 45 | // Transform model list (returns map[string]any directly, no marshaling) |
| 46 | response, err := channelHandler.TransformModelList(c.Request, decompressed, group) |
| 47 | if err != nil { |
| 48 | logrus.WithError(err).Error("Failed to transform model list") |
| 49 | c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to process response"}) |
| 50 | return |
| 51 | } |
| 52 | |
| 53 | c.JSON(http.StatusOK, response) |
| 54 | } |
no test coverage detected