allow path_prefix on proxied url

This commit is contained in:
Andrea Spacca 2021-11-13 10:14:35 +01:00
parent e615be63e4
commit d99e24abb6
1 changed files with 8 additions and 2 deletions

10
main.go
View File

@ -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)