Skip to content

Commit fc38687

Browse files
committed
代理请求要包含查询字符串
1 parent 5e9c79f commit fc38687

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func main() {
2828
}
2929
log.Println("Target domain: ", target)
3030
http.HandleFunc("/", handleRequest)
31-
http.ListenAndServe(":9000", nil)
31+
http.ListenAndServe(":9001", nil)
3232
}
3333

3434
func handleRequest(w http.ResponseWriter, r *http.Request) {
@@ -44,8 +44,11 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
4444
newPath := strings.Replace(r.URL.Path, "/release", "", 1)
4545
newPath = strings.Replace(newPath, "/test", "", 1)
4646

47-
// 拼接目标URL
47+
// 拼接目标URL(带上查询字符串,如果有的话)
4848
targetURL := target + newPath
49+
if r.URL.RawQuery != "" {
50+
targetURL += "?" + r.URL.RawQuery
51+
}
4952

5053
// 创建代理HTTP请求
5154
proxyReq, err := http.NewRequest(r.Method, targetURL, r.Body)

scf_bootstrap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
./main
44

5-
# support other domain than https://api.openai.com (default)
5+
# support other domain than https://api.openai.com(default)
66
# ./main -domain=https://api.other.com

0 commit comments

Comments
 (0)