From 5a1e3830e3d16037f8205db88bdb04f05ac6e7fe Mon Sep 17 00:00:00 2001 From: Jonas Roussel Date: Fri, 30 Aug 2024 14:04:33 +0200 Subject: [PATCH] fix(tools): script url parsing --- tools/script.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/script.go b/tools/script.go index d6cca8c..d454d76 100644 --- a/tools/script.go +++ b/tools/script.go @@ -2,10 +2,12 @@ package tools import ( "errors" + "fmt" "log" "net/http" "os" "regexp" + "strings" "github.com/dop251/goja" ) @@ -49,6 +51,15 @@ func LoadDynamicTarget() { } func CallDynamicTarget(req *http.Request) string { + host := req.Host + + path := req.URL.EscapedPath() + if path != "/" { + path = strings.TrimRight(path, "/") + } + + url := fmt.Sprintf("https://%s%s", host, path) + query := map[string]string{} for k, v := range req.URL.Query() { query[k] = v[0] @@ -59,5 +70,5 @@ func CallDynamicTarget(req *http.Request) string { headers[k] = v[0] } - return proxyCallback(req.URL.String(), req.URL.Host, req.URL.EscapedPath(), query, headers) + return proxyCallback(url, host, path, query, headers) }