fix: serve sender hls public path

Accept the current /sender/hls route in the Sender HLS plug while preserving the legacy plugin-slug path. Add direct plug coverage for both path shapes.
This commit is contained in:
2026-06-18 02:16:57 +02:00
parent 3e288a7e95
commit cdbfef7cd3
2 changed files with 63 additions and 0 deletions
+5
View File
@@ -8,6 +8,11 @@ defmodule TribeOne.TribesPlugin.SenderWeb.HLSPlug do
def init(opts), do: opts
def call(%{method: method, path_info: ["sender", "hls" | path_segments]} = conn, _opts)
when method in ["GET", "HEAD"] do
serve(conn, path_segments)
end
def call(
%{method: method, path_info: ["tribe-one-sender", "hls" | path_segments]} = conn,
_opts
+58
View File
@@ -0,0 +1,58 @@
defmodule TribeOne.TribesPlugin.Sender.HLSPlugTest do
use ExUnit.Case, async: false
import Plug.Conn
import Plug.Test
alias TribeOne.TribesPlugin.Sender.{HLS, Stats}
alias TribeOne.TribesPlugin.SenderWeb.HLSPlug
setup do
if Process.whereis(Stats) == nil do
start_supervised!(Stats)
end
:ok = Stats.reset()
root =
Path.join(System.tmp_dir!(), "sender-hls-plug-test-#{System.unique_integer([:positive])}")
path = Path.join([root, "streams", "stream", "generation"])
File.mkdir_p!(path)
File.write!(Path.join(path, "media.m3u8"), "#EXTM3U\n")
previous = Application.get_env(:sender, HLS, [])
Application.put_env(:sender, HLS, Keyword.put(previous, :spool_root, root))
on_exit(fn ->
Application.put_env(:sender, HLS, previous)
File.rm_rf!(root)
end)
:ok
end
test "serves the current public sender HLS path" do
conn =
:get
|> conn("/sender/hls/streams/stream/generation/media.m3u8")
|> HLSPlug.call([])
assert conn.halted
assert conn.status == 200
assert conn.resp_body == "#EXTM3U\n"
assert [content_type] = get_resp_header(conn, "content-type")
assert content_type =~ "application/vnd.apple.mpegurl"
end
test "keeps the legacy plugin slug HLS path working" do
conn =
:get
|> conn("/tribe-one-sender/hls/streams/stream/generation/media.m3u8")
|> HLSPlug.call([])
assert conn.halted
assert conn.status == 200
assert conn.resp_body == "#EXTM3U\n"
end
end