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:
parent
439c3422fb
commit
143d5ef8ab
@ -152,6 +152,7 @@ type JsonConfig struct {
|
|||||||
} `json:"_rate_limit"`
|
} `json:"_rate_limit"`
|
||||||
IgnoreInvalidCQCode bool `json:"ignore_invalid_cqcode"`
|
IgnoreInvalidCQCode bool `json:"ignore_invalid_cqcode"`
|
||||||
ForceFragmented bool `json:"force_fragmented"`
|
ForceFragmented bool `json:"force_fragmented"`
|
||||||
|
ProxyRewrite string `json:"proxy_rewrite"`
|
||||||
HeartbeatInterval time.Duration `json:"heartbeat_interval"`
|
HeartbeatInterval time.Duration `json:"heartbeat_interval"`
|
||||||
HttpConfig *GoCQHttpConfig `json:"http_config"`
|
HttpConfig *GoCQHttpConfig `json:"http_config"`
|
||||||
WSConfig *GoCQWebsocketConfig `json:"ws_config"`
|
WSConfig *GoCQWebsocketConfig `json:"ws_config"`
|
||||||
|
@ -5,7 +5,9 @@ import (
|
|||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -14,8 +16,28 @@ import (
|
|||||||
|
|
||||||
var client = &http.Client{
|
var client = &http.Client{
|
||||||
Timeout: time.Second * 15,
|
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) {
|
func GetBytes(url string) ([]byte, error) {
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
1
main.go
1
main.go
@ -319,6 +319,7 @@ func main() {
|
|||||||
if conf.WebUi.Host == "" {
|
if conf.WebUi.Host == "" {
|
||||||
conf.WebUi.Host = "127.0.0.1"
|
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)
|
b := server.WebServer.Run(fmt.Sprintf("%s:%d", conf.WebUi.Host, conf.WebUi.WebUiPort), cli)
|
||||||
c := server.Console
|
c := server.Console
|
||||||
r := server.Restart
|
r := server.Restart
|
||||||
|
Loading…
x
Reference in New Issue
Block a user