fix: extract copyProxyResponseBody to reduce cyclomatic complexity

This commit is contained in:
2026-06-19 13:39:43 +02:00
committed by Milas Holsting
parent e1ab6e714e
commit bb37b8e18a

View File

@@ -47,12 +47,15 @@ func (h *PlaybackHandler) HandleProxyStream(c *gin.Context) {
copyProxyHeaders(c.Writer.Header(), resp.Header) copyProxyHeaders(c.Writer.Header(), resp.Header)
c.Status(resp.StatusCode) c.Status(resp.StatusCode)
if n, err := io.Copy(c.Writer, resp.Body); err != nil { copyProxyResponseBody(c, resp.Body, targetURL)
if errors.Is(err, context.Canceled) || c.Request.Context().Err() != nil { }
return
} func copyProxyResponseBody(c *gin.Context, body io.Reader, targetURL string) {
observability.WarnContext(c.Request.Context(), "proxy_stream_copy_failed", "playback", "", map[string]any{"target_url": targetURL, "bytes_copied": n}, err) n, err := io.Copy(c.Writer, body)
if err == nil || errors.Is(err, context.Canceled) || c.Request.Context().Err() != nil {
return
} }
observability.WarnContext(c.Request.Context(), "proxy_stream_copy_failed", "playback", "", map[string]any{"target_url": targetURL, "bytes_copied": n}, err)
} }
func (h *PlaybackHandler) writeProxyPlaylist(c *gin.Context, resp *http.Response, targetURL string, referer string) { func (h *PlaybackHandler) writeProxyPlaylist(c *gin.Context, resp *http.Response, targetURL string, referer string) {