From d99e24abb66159c1fddb4b04a4a1147ce674fa97 Mon Sep 17 00:00:00 2001 From: Andrea Spacca Date: Sat, 13 Nov 2021 10:14:35 +0100 Subject: [PATCH] allow path_prefix on proxied url --- main.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index d4e6fd5..12a736d 100644 --- a/main.go +++ b/main.go @@ -52,6 +52,8 @@ var allowed_hosts = []string{ "lbryplayer.xyz", } +var path_prefix = "" + var manifest_re = regexp.MustCompile(`(?m)URI="([^"]+)"`) type requesthandler struct{} @@ -169,7 +171,7 @@ func (*requesthandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { if !strings.HasPrefix(line, "https://") && (strings.HasSuffix(line, ".m3u8") || strings.HasSuffix(line, ".ts")) { path := reqUrl.EscapedPath() path = path[0 : strings.LastIndex(path, "/")+1] - line = "https://" + reqUrl.Hostname() + path + line + line = "https://" + reqUrl.Hostname() + path_prefix + path + line } if strings.HasPrefix(line, "https://") { lines[i] = RelativeUrl(line) @@ -247,10 +249,14 @@ func RelativeUrl(in string) (newurl string) { segment_query := segment_url.Query() segment_query.Set("host", segment_url.Hostname()) segment_url.RawQuery = segment_query.Encode() - return segment_url.RequestURI() + return path_prefix + segment_url.RequestURI() } func main() { + if len(os.Args) == 2 { + path_prefix = os.Args[1] + } + socket := "socket" + string(os.PathSeparator) + "http-proxy.sock" syscall.Unlink(socket) listener, err := net.Listen("unix", socket)