Skip to content

Commit

Permalink
proxied fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
josStorer committed Mar 26, 2024
1 parent a15c4bd commit 288724a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions backend-golang/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
};
}

Expand Down

0 comments on commit 288724a

Please sign in to comment.