diff --git a/global/config.go b/global/config.go index 68a6e1e..25075f1 100644 --- a/global/config.go +++ b/global/config.go @@ -152,6 +152,7 @@ type JsonConfig struct { } `json:"_rate_limit"` IgnoreInvalidCQCode bool `json:"ignore_invalid_cqcode"` ForceFragmented bool `json:"force_fragmented"` + ProxyRewrite string `json:"proxy_rewrite"` HeartbeatInterval time.Duration `json:"heartbeat_interval"` HttpConfig *GoCQHttpConfig `json:"http_config"` WSConfig *GoCQWebsocketConfig `json:"ws_config"` diff --git a/global/net.go b/global/net.go index 1495fb1..d10bb1e 100644 --- a/global/net.go +++ b/global/net.go @@ -5,7 +5,9 @@ import ( "compress/gzip" "fmt" "io/ioutil" + "net" "net/http" + "net/url" "strings" "time" @@ -14,8 +16,28 @@ import ( var client = &http.Client{ Timeout: time.Second * 15, + Transport: &http.Transport{ + Proxy: func(request *http.Request) (u *url.URL, e error) { + if Proxy == "" { + return http.ProxyFromEnvironment(request) + } + return url.Parse(Proxy) + }, + DialContext: (&net.Dialer{ + Timeout: 30 * time.Second, + KeepAlive: 30 * time.Second, + DualStack: true, + }).DialContext, + ForceAttemptHTTP2: true, + MaxIdleConns: 100, + IdleConnTimeout: 90 * time.Second, + TLSHandshakeTimeout: 10 * time.Second, + ExpectContinueTimeout: 1 * time.Second, + }, } +var Proxy string + func GetBytes(url string) ([]byte, error) { req, err := http.NewRequest("GET", url, nil) if err != nil { diff --git a/main.go b/main.go index d6bbcee..0972ba4 100644 --- a/main.go +++ b/main.go @@ -319,6 +319,7 @@ func main() { if conf.WebUi.Host == "" { conf.WebUi.Host = "127.0.0.1" } + global.Proxy = conf.ProxyRewrite b := server.WebServer.Run(fmt.Sprintf("%s:%d", conf.WebUi.Host, conf.WebUi.WebUiPort), cli) c := server.Console r := server.Restart