mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-08 01:20:27 +00:00
fix: tracker cdn retry issue
This commit is contained in:
1 parent
20130ae6d0
commit
7fdba12376
3 files changed
+30
-11
No files matched your search
+9
-4
@@ -147,12 +147,12 @@ func PutConfig(w http.ResponseWriter, r *http.Request) {
|
||||
func DoProxy(w http.ResponseWriter, r *http.Request) {
|
||||
target := r.Header.Get("X-Target-Uri")
|
||||
if target == "" {
|
||||
WriteJson(w, model.NewErrorResult("param invalid: X-Target-Uri", model.CodeInvalidParam))
|
||||
writeError(w, "param invalid: X-Target-Uri")
|
||||
return
|
||||
}
|
||||
targetUrl, err := url.Parse(target)
|
||||
if err != nil {
|
||||
WriteJson(w, model.NewErrorResult(err.Error()))
|
||||
writeError(w, err.Error())
|
||||
return
|
||||
}
|
||||
r.RequestURI = ""
|
||||
@@ -160,7 +160,7 @@ func DoProxy(w http.ResponseWriter, r *http.Request) {
|
||||
r.Host = targetUrl.Host
|
||||
resp, err := http.DefaultClient.Do(r)
|
||||
if err != nil {
|
||||
WriteJson(w, model.NewErrorResult(err.Error()))
|
||||
writeError(w, err.Error())
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
@@ -179,11 +179,16 @@ func DoProxy(w http.ResponseWriter, r *http.Request) {
|
||||
reader = resp.Body
|
||||
}
|
||||
if _, err := io.Copy(w, reader); err != nil {
|
||||
WriteJson(w, model.NewErrorResult(err.Error()))
|
||||
writeError(w, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func writeError(w http.ResponseWriter, msg string) {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(msg))
|
||||
}
|
||||
|
||||
func getServerConfig() *download.DownloaderStoreConfig {
|
||||
_, cfg, _ := Downloader.GetConfig()
|
||||
return cfg
|
||||
|
||||
Reference in new issue
Block a user