mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
🐛 S3/WebDAV 数据同步无法使用代理 Fix https://github.com/siyuan-note/siyuan/issues/6695
This commit is contained in:
parent
255a9c1e01
commit
f38e053702
2 changed files with 27 additions and 3 deletions
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"crypto/tls"
|
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -824,7 +823,7 @@ func newRepository() (ret *dejavu.Repo, err error) {
|
||||||
case conf.ProviderSiYuan:
|
case conf.ProviderSiYuan:
|
||||||
cloudRepo = cloud.NewSiYuan(&cloud.BaseCloud{Conf: cloudConf})
|
cloudRepo = cloud.NewSiYuan(&cloud.BaseCloud{Conf: cloudConf})
|
||||||
case conf.ProviderS3:
|
case conf.ProviderS3:
|
||||||
s3HTTPClient := &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: cloudConf.S3.SkipTlsVerify}}}
|
s3HTTPClient := &http.Client{Transport: util.NewTransport(cloudConf.S3.SkipTlsVerify)}
|
||||||
s3HTTPClient.Timeout = 30 * time.Second
|
s3HTTPClient.Timeout = 30 * time.Second
|
||||||
cloudRepo = cloud.NewS3(&cloud.BaseCloud{Conf: cloudConf}, s3HTTPClient)
|
cloudRepo = cloud.NewS3(&cloud.BaseCloud{Conf: cloudConf}, s3HTTPClient)
|
||||||
case conf.ProviderWebDAV:
|
case conf.ProviderWebDAV:
|
||||||
|
|
@ -834,7 +833,7 @@ func newRepository() (ret *dejavu.Repo, err error) {
|
||||||
webdavClient.SetHeader("Authorization", auth)
|
webdavClient.SetHeader("Authorization", auth)
|
||||||
webdavClient.SetHeader("User-Agent", util.UserAgent)
|
webdavClient.SetHeader("User-Agent", util.UserAgent)
|
||||||
webdavClient.SetTimeout(30 * time.Second)
|
webdavClient.SetTimeout(30 * time.Second)
|
||||||
webdavClient.SetTransport(&http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: cloudConf.WebDAV.SkipTlsVerify}})
|
webdavClient.SetTransport(util.NewTransport(cloudConf.WebDAV.SkipTlsVerify))
|
||||||
cloudRepo = cloud.NewWebDAV(&cloud.BaseCloud{Conf: cloudConf}, webdavClient)
|
cloudRepo = cloud.NewWebDAV(&cloud.BaseCloud{Conf: cloudConf}, webdavClient)
|
||||||
default:
|
default:
|
||||||
err = fmt.Errorf("unknown cloud provider [%d]", Conf.Sync.Provider)
|
err = fmt.Errorf("unknown cloud provider [%d]", Conf.Sync.Provider)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,12 @@
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
@ -48,3 +53,23 @@ func JsonArg(c *gin.Context, result *gulu.Result) (arg map[string]interface{}, o
|
||||||
ok = true
|
ok = true
|
||||||
return
|
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
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue