Skip to content

Commit

Permalink
fix(tools): script url parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasroussel committed Aug 30, 2024
1 parent 6c239f8 commit 5a1e383
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tools/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package tools

import (
"errors"
"fmt"
"log"
"net/http"
"os"
"regexp"
"strings"

"github.com/dop251/goja"
)
Expand Down Expand Up @@ -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]
Expand All @@ -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)
}

0 comments on commit 5a1e383

Please sign in to comment.