From 288724adef5fbb2c483854ad40b2f0943265b99c Mon Sep 17 00:00:00 2001 From: josc146 Date: Tue, 26 Mar 2024 22:25:24 +0800 Subject: [PATCH] proxied fetch --- backend-golang/app.go | 6 ++++++ frontend/src/utils/index.tsx | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/backend-golang/app.go b/backend-golang/app.go index be2d89a..4ea1620 100644 --- a/backend-golang/app.go +++ b/backend-golang/app.go @@ -58,6 +58,11 @@ func (a *App) newFetchProxy() { Director: func(req *http.Request) { realTarget := req.Header.Get("Real-Target") if realTarget != "" { + realTarget, err := url.PathUnescape(realTarget) + if err != nil { + log.Printf("Error decoding target URL: %v\n", err) + return + } target, err := url.Parse(realTarget) if err != nil { log.Printf("Error parsing target URL: %v\n", err) @@ -73,6 +78,7 @@ func (a *App) newFetchProxy() { req.URL.Scheme = target.Scheme req.URL.Host = target.Host req.URL.Path = target.Path + req.URL.RawQuery = url.PathEscape(target.RawQuery) log.Println("Proxying to", realTarget) } else { log.Println("Real-Target header is missing") diff --git a/frontend/src/utils/index.tsx b/frontend/src/utils/index.tsx index 93fd51a..27a5ed8 100644 --- a/frontend/src/utils/index.tsx +++ b/frontend/src/utils/index.tsx @@ -329,7 +329,7 @@ export async function getReqUrl(port: number, path: string, isCore: boolean = fa await GetProxyPort().then(p => commonStore.setProxyPort(p)); return { url: `http://127.0.0.1:${commonStore.proxyPort}`, - headers: { 'Real-Target': realUrl } + headers: { 'Real-Target': encodeURIComponent(realUrl) } }; }