1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 03:23:49 +08:00

feature proxy rewrite.

This commit is contained in:
Mrs4s 2020-11-24 19:03:37 +08:00
parent 439c3422fb
commit 143d5ef8ab
3 changed files with 24 additions and 0 deletions

View File

@ -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"`

View File

@ -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 {

View File

@ -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