From 0d57a855f4d7fbb70e7387bd20f07d84fc88b312 Mon Sep 17 00:00:00 2001 From: Ingo Oppermann Date: Mon, 4 Nov 2024 16:28:44 +0100 Subject: [PATCH] Use better name for variable --- http/middleware/session/HLS.go | 13 ++++++++----- http/middleware/session/session.go | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/http/middleware/session/HLS.go b/http/middleware/session/HLS.go index f7939f31..379dbd41 100644 --- a/http/middleware/session/HLS.go +++ b/http/middleware/session/HLS.go @@ -33,7 +33,10 @@ func (h *handler) handleHLSIngress(c echo.Context, _ string, data map[string]int req := c.Request() path := req.URL.Path - if strings.HasSuffix(path, ".m3u8") { + isM3U8 := strings.HasSuffix(path, ".m3u8") + isSegment := strings.HasSuffix(path, ".ts") || strings.HasSuffix(path, ".mp4") + + if isM3U8 { // Read out the path of the .ts files and look them up in the ts-map. // Add it as ingress for the respective "sessionId". The "sessionId" is the .m3u8 file name. reader := req.Body @@ -81,7 +84,7 @@ func (h *handler) handleHLSIngress(c echo.Context, _ string, data map[string]int mem.Put(r.buffer) }() - } else if strings.HasSuffix(path, ".ts") || strings.HasSuffix(path, ".mp4") { + } else if isSegment { // Get the size of the .ts file and store it in the ts-map for later use. reader := req.Body r := &bodysizeReader{ @@ -117,7 +120,7 @@ func (h *handler) handleHLSEgress(c echo.Context, _ string, data map[string]inte sessionID := c.QueryParam("session") isM3U8 := strings.HasSuffix(path, ".m3u8") - isTS := strings.HasSuffix(path, ".ts") || strings.HasSuffix(path, ".mp4") + isSegment := strings.HasSuffix(path, ".ts") || strings.HasSuffix(path, ".mp4") rewrite := false @@ -213,7 +216,7 @@ func (h *handler) handleHLSEgress(c echo.Context, _ string, data map[string]inte mem.Put(rewriter.buffer) } - if isM3U8 || isTS { + if isM3U8 || isSegment { if res.Status >= 200 && res.Status < 300 { // Collect how many bytes we've written in this session buffer := mem.Get() @@ -221,7 +224,7 @@ func (h *handler) handleHLSEgress(c echo.Context, _ string, data map[string]inte h.hlsEgressCollector.Egress(sessionID, res.Size) mem.Put(buffer) - if isTS { + if isSegment { // Activate the session. If the session is already active, this is a noop h.hlsEgressCollector.Activate(sessionID) } diff --git a/http/middleware/session/session.go b/http/middleware/session/session.go index 9cd77955..53083ee2 100644 --- a/http/middleware/session/session.go +++ b/http/middleware/session/session.go @@ -104,9 +104,9 @@ func NewWithConfig(config Config) echo.MiddlewareFunc { data["ip"] = ip isM3U8 := strings.HasSuffix(path, ".m3u8") - isTS := strings.HasSuffix(path, ".ts") + isSegment := strings.HasSuffix(path, ".ts") || strings.HasSuffix(path, ".mp4") - if isM3U8 || isTS { + if isM3U8 || isSegment { return h.handleHLS(c, ctxuser, data, next) }