From e6a0f39557c8e7e6e4c4be8be56275b156b7920a Mon Sep 17 00:00:00 2001 From: Andrea Spacca Date: Wed, 17 Nov 2021 14:14:51 +0100 Subject: [PATCH] Allow to prepend a path prefix in case proxy is not hosted on root of the domain (#4) * allow path_prefix on proxied url * add debug print, skip Authorization header * remove debug print * cr fixes --- main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index d4e6fd5..d24cd18 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{} @@ -190,7 +192,7 @@ func (*requesthandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { func copyHeaders(from http.Header, to http.Header) { // Loop over header names for name, values := range from { - if name != "Content-Length" && name != "Accept-Encoding" { + if name != "Content-Length" && name != "Accept-Encoding" && name != "Authorization" { // Loop over all values for the name. for _, value := range values { to.Set(name, value) @@ -247,10 +249,12 @@ 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() { + path_prefix = os.Getenv("PREFIX_PATH") + socket := "socket" + string(os.PathSeparator) + "http-proxy.sock" syscall.Unlink(socket) listener, err := net.Listen("unix", socket)