设置代理切换时不再需要重启 https://github.com/siyuan-note/siyuan/issues/6787
This commit is contained in:
Liang Ding 2022-12-05 22:59:59 +08:00
parent 9f463fec1e
commit 74453a20bb
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
8 changed files with 40 additions and 59 deletions

View file

@ -17,12 +17,7 @@
package util
import (
"context"
"crypto/tls"
"net"
"net/http"
"strings"
"time"
"github.com/88250/gulu"
"github.com/gin-gonic/gin"
@ -53,23 +48,3 @@ func JsonArg(c *gin.Context, result *gulu.Result) (arg map[string]interface{}, o
ok = true
return
}
func NewTransport(skipTlsVerify bool) *http.Transport {
return &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: defaultTransportDialContext(&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}),
ForceAttemptHTTP2: true,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
TLSClientConfig: &tls.Config{InsecureSkipVerify: skipTlsVerify}}
}
func defaultTransportDialContext(dialer *net.Dialer) func(context.Context, string, string) (net.Conn, error) {
return dialer.DialContext
}

View file

@ -37,7 +37,7 @@ func GetRhyResult(force bool) (map[string]interface{}, error) {
return cachedRhyResult, nil
}
request := httpclient.NewCloudRequest()
request := httpclient.NewCloudRequest30s()
_, err := request.SetResult(&cachedRhyResult).Get(AliyunServer + "/apis/siyuan/version?ver=" + Ver)
if nil != err {
logging.LogErrorf("get version info failed: %s", err)

View file

@ -25,6 +25,7 @@ import (
"github.com/88250/gulu"
"github.com/denisbrodbeck/machineid"
"github.com/siyuan-note/httpclient"
"github.com/siyuan-note/logging"
)
@ -87,6 +88,8 @@ func SetNetworkProxy(proxyURL string) {
} else {
logging.LogInfof("use network proxy [system]")
}
httpclient.CloseIdleConnections()
}
const (