From 4c7d6241e2a8305b365049c057c0e28692aa3c22 Mon Sep 17 00:00:00 2001 From: Andriy Biletsky Date: Mon, 2 Dec 2024 15:32:22 +0700 Subject: [PATCH] Remove range header check on head request --- player/http_handlers.go | 6 ++---- player/http_handlers_test.go | 8 ++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/player/http_handlers.go b/player/http_handlers.go index 9190602..8061235 100644 --- a/player/http_handlers.go +++ b/player/http_handlers.go @@ -265,9 +265,7 @@ func (h *RequestHandler) Handle(c *gin.Context) { } } - if c.GetHeader("range") == "" { - metrics.StreamsDelivered.WithLabelValues(metrics.StreamOriginal).Inc() - } + metrics.StreamsDelivered.WithLabelValues(metrics.StreamOriginal).Inc() err = stream.PrepareForReading() addBreadcrumb(c.Request, "sdk", fmt.Sprintf("retrieve %v", uri)) @@ -437,5 +435,5 @@ func getPlaylistURL(fullPath string, query url.Values, tcPath string, stream *St func fitForTranscoder(c *gin.Context, s *Stream) bool { return (strings.HasPrefix(c.FullPath(), "/api/v4/") || ((reV5StartEndpoint.MatchString(c.FullPath()) || reV6StartEndpoint.MatchString(c.FullPath())) && c.Request.Method == http.MethodHead)) && - strings.HasPrefix(s.ContentType, "video/") && c.GetHeader("range") == "" + strings.HasPrefix(s.ContentType, "video/") } diff --git a/player/http_handlers_test.go b/player/http_handlers_test.go index 9297a7a..52817f8 100644 --- a/player/http_handlers_test.go +++ b/player/http_handlers_test.go @@ -372,6 +372,14 @@ func Test_fitForTranscoder(t *testing.T) { require.NoError(t, err) assert.True(t, fitForTranscoder(c, s)) + r, _ = http.NewRequest(http.MethodHead, "https://cdn.lbryplayer.xyz/v5/streams/start/6769855a9aa43b67086f9ff3c1a5bacb5698a27a/abcabc", nil) + c.Request = r + r.Header.Add("Range", "bytes=0-13337") + e.HandleContext(c) + s, err = p.ResolveStream("6769855a9aa43b67086f9ff3c1a5bacb5698a27a") + require.NoError(t, err) + assert.True(t, fitForTranscoder(c, s)) + r, _ = http.NewRequest(http.MethodGet, "https://cdn.lbryplayer.xyz/v5/streams/original/6769855a9aa43b67086f9ff3c1a5bacb5698a27a/abcabc", nil) c.Request = r e.HandleContext(c)