Skip to content

Respect standard proxy header for hostname when generating M3U playlist#611

Merged
tsynik merged 2 commits intoYouROK:masterfrom
dtruebin:bugfix/m3u-proxy-host
Dec 29, 2025
Merged

Respect standard proxy header for hostname when generating M3U playlist#611
tsynik merged 2 commits intoYouROK:masterfrom
dtruebin:bugfix/m3u-proxy-host

Conversation

@dtruebin
Copy link
Contributor

@dtruebin dtruebin commented Dec 25, 2025

Fixes #610

First commit makes preparations, with no effective change, whereas the 2nd has the actual fix.
This is my first exposure to Go, so pardon me for not writing any tests 🥺

Manual testing done:

  1. Default address — playlist entries point to the proper address 🟢

     $ curl \
     > 'http://localhost:8090/stream/Big%20Buck%20Bunny.m3u?link=dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&m3u'
     #EXTM3U
     #EXTINF:0,Big Buck Bunny.mp4
     #EXTVLCOPT:input-slave=http://localhost:8090/stream/Big%20Buck%20Bunny.en.srt?link=dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&index=1&play#http://localhost:8090/stream/poster.jpg?link=dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&index=3&play#
     http://localhost:8090/stream/Big%20Buck%20Bunny.mp4?link=dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&index=2&play
    
  2. Pretend we are behind a reverse proxy — playlist entries point to the proper address 🟢

     $ curl \
     > -H 'X-Forwarded-Proto: https' \
     > -H 'X-Forwarded-Host: torr.example.org' \
     > 'http://localhost:8090/stream/Big%20Buck%20Bunny.m3u?link=dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&m3u'
     #EXTM3U
     #EXTINF:0,Big Buck Bunny.mp4
     #EXTVLCOPT:input-slave=https://torr.example.org/stream/Big%20Buck%20Bunny.en.srt?link=dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&index=1&play#https://torr.example.org/stream/poster.jpg?link=dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&index=3&play#
     https://torr.example.org/stream/Big%20Buck%20Bunny.mp4?link=dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&index=2&play
    

    For comparison, at 28f4f94 (current master) — playlist entries point to the proper schema 🟢 but wrong address 🔴

     $ curl \
     > -H 'X-Forwarded-Proto: https' \
     > -H 'X-Forwarded-Host: torr.example.org' \
     > 'http://localhost:8090/stream/Big%20Buck%20Bunny.m3u?link=dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&m3u'
     #EXTM3U
     #EXTINF:0,Big Buck Bunny.mp4
     #EXTVLCOPT:input-slave=https://localhost:8090/stream/Big%20Buck%20Bunny.en.srt?link=dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&index=1&play#https://localhost:8090/stream/poster.jpg?link=dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&index=3&play#
     https://localhost:8090/stream/Big%20Buck%20Bunny.mp4?link=dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&index=2&play
    

Rely on Gin's location middleware for retrieval of host/port combination,
so that HTTP headers (such as ones passed from a reverse proxy) are also
taken into account.

Only `/stream` API seems to be relevant for YouROK#610 (see web's Hosts.js)
but fix `/playlist*` APIs as well while we're at it.

It seems that Media Station X stuff (`msx.go`) may benefit from this too
but keep it intact for now as it's offtopic.
Respect standard proxy host header (`X-Forwarded-Host`) when building
playlist content.
See gin-contrib/location#15

Closes YouROK#610
@tsynik tsynik merged commit 8a612fa into YouROK:master Dec 29, 2025
@dtruebin dtruebin deleted the bugfix/m3u-proxy-host branch December 29, 2025 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Generated M3U playlist entries have internal host:port when running behind reverse proxy

2 participants