更新 proxy/handler.go
This commit is contained in:
@@ -144,35 +144,6 @@ func (h *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// 处理 404:尝试从 Referer 提取正确路径
|
||||
if resp.StatusCode == 404 {
|
||||
if referer := r.Header.Get("Referer"); referer != "" && strings.Contains(referer, "/p/"+token) {
|
||||
if u, err := url.Parse(targetURL); err == nil && u.Host != "" {
|
||||
// 直接使用原始 targetURL 的 host + path
|
||||
baseURL := u.Scheme + "://" + u.Host
|
||||
correctPath := u.Path
|
||||
if u.RawQuery != "" {
|
||||
correctPath += "?" + u.RawQuery
|
||||
}
|
||||
|
||||
newTargetURL := baseURL + correctPath
|
||||
|
||||
// 避免重复请求相同 URL
|
||||
if newTargetURL != targetURL {
|
||||
retryReq, _ := http.NewRequest(r.Method, newTargetURL, nil)
|
||||
h.setProxyHeaders(retryReq, r)
|
||||
|
||||
if retryResp, err := client.Do(retryReq); err == nil && retryResp.StatusCode == 200 {
|
||||
resp.Body.Close()
|
||||
resp = retryResp
|
||||
defer resp.Body.Close()
|
||||
log.Printf("404 retry success: %s -> %s", targetURL, newTargetURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
body, err := h.readResponseBody(resp)
|
||||
if err != nil {
|
||||
log.Printf("Failed to read response: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user