mirror of
https://github.com/nitezs/sub2clash.git
synced 2025-04-03 20:23:45 +08:00
Compare commits
2 Commits
d4d7010d8f
...
db00433931
Author | SHA1 | Date | |
---|---|---|---|
db00433931 | |||
![]() |
5b3a12f00d |
@ -2,6 +2,7 @@ package common
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -28,10 +29,12 @@ func Get(url string, options ...GetOption) (resp *http.Response, err error) {
|
|||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
option(&getConfig)
|
option(&getConfig)
|
||||||
}
|
}
|
||||||
|
var req *http.Request
|
||||||
|
var get *http.Response
|
||||||
for haveTried < retryTimes {
|
for haveTried < retryTimes {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
//client.Timeout = time.Second * 10
|
//client.Timeout = time.Second * 10
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err = http.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
haveTried++
|
haveTried++
|
||||||
time.Sleep(retryDelay)
|
time.Sleep(retryDelay)
|
||||||
@ -40,13 +43,12 @@ func Get(url string, options ...GetOption) (resp *http.Response, err error) {
|
|||||||
if getConfig.userAgent != "" {
|
if getConfig.userAgent != "" {
|
||||||
req.Header.Set("User-Agent", getConfig.userAgent)
|
req.Header.Set("User-Agent", getConfig.userAgent)
|
||||||
}
|
}
|
||||||
get, err := client.Do(req)
|
get, err = client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
haveTried++
|
haveTried++
|
||||||
time.Sleep(retryDelay)
|
time.Sleep(retryDelay)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if get != nil && get.ContentLength > config.Default.RequestMaxFileSize {
|
if get != nil && get.ContentLength > config.Default.RequestMaxFileSize {
|
||||||
return nil, errors.New("文件过大")
|
return nil, errors.New("文件过大")
|
||||||
}
|
}
|
||||||
@ -54,5 +56,5 @@ func Get(url string, options ...GetOption) (resp *http.Response, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, fmt.Errorf("请求失败:%v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user