fix: make TlsInsecureSkipVerify enable for all request (#4386)

This commit is contained in:
XYUU
2023-05-14 17:05:47 +08:00
committed by GitHub
parent 3c4c2ad4e0
commit a3446720a2
11 changed files with 65 additions and 39 deletions

View File

@ -8,7 +8,9 @@ import (
"os"
"strconv"
"strings"
"sync"
"github.com/alist-org/alist/v3/drivers/base"
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/pkg/utils"
@ -16,16 +18,23 @@ import (
log "github.com/sirupsen/logrus"
)
var HttpClient = &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
if len(via) >= 10 {
return errors.New("stopped after 10 redirects")
func HttpClient() *http.Client {
once.Do(func() {
httpClient = base.NewHttpClient()
httpClient.CheckRedirect = func(req *http.Request, via []*http.Request) error {
if len(via) >= 10 {
return errors.New("stopped after 10 redirects")
}
req.Header.Del("Referer")
return nil
}
req.Header.Del("Referer")
return nil
},
})
return httpClient
}
var once sync.Once
var httpClient *http.Client
func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.Obj) error {
// read data with native
var err error
@ -90,7 +99,7 @@ func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.
for h, val := range link.Header {
req.Header[h] = val
}
res, err := HttpClient.Do(req)
res, err := HttpClient().Do(req)
if err != nil {
return err
}