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)
c.Status(resp.StatusCode)
if n, err := io.Copy(c.Writer, resp.Body); err != nil {
if 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)
copyProxyResponseBody(c, resp.Body, targetURL)
}
func copyProxyResponseBody(c *gin.Context, body io.Reader, targetURL string) {
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) {