Skip to content

Commit 42606a8

Browse files
committed
internal/download: disable http when not visiting go-cqhttp.org
1 parent 1ed675d commit 42606a8

4 files changed

Lines changed: 32 additions & 7 deletions

File tree

‎cmd/gocq/main.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ func LoginInteract() {
364364
})
365365
saveToken()
366366
cli.AllowSlider = true
367-
download.SetGlobalTimeout(time.Duration(base.HTTPTimeout) * time.Second) // 在登录完成后设置, 防止在堵塞协议更新
367+
download.SetTimeout(time.Duration(base.HTTPTimeout) * time.Second) // 在登录完成后设置, 防止在堵塞协议更新
368368
log.Infof("登录成功 欢迎使用: %v", cli.Nickname)
369369
log.Info("开始加载好友列表...")
370370
global.Check(cli.ReloadFriendList(), true)

‎internal/download/download.go‎

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package download
44
import (
55
"bufio"
66
"compress/gzip"
7+
"crypto/tls"
78
"fmt"
89
"io"
910
"net/http"
@@ -22,15 +23,28 @@ import (
2223

2324
var client = &http.Client{
2425
Transport: &http.Transport{
25-
Proxy: func(request *http.Request) (u *url.URL, e error) {
26+
Proxy: func(request *http.Request) (*url.URL, error) {
2627
if base.Proxy == "" {
2728
return http.ProxyFromEnvironment(request)
2829
}
2930
return url.Parse(base.Proxy)
3031
},
31-
ForceAttemptHTTP2: false,
32-
MaxConnsPerHost: 0,
33-
MaxIdleConns: 0,
32+
// Disable http2
33+
TLSNextProto: map[string]func(authority string, c *tls.Conn) http.RoundTripper{},
34+
MaxIdleConnsPerHost: 999,
35+
},
36+
Timeout: time.Second * 5,
37+
}
38+
39+
var clienth2 = &http.Client{
40+
Transport: &http.Transport{
41+
Proxy: func(request *http.Request) (*url.URL, error) {
42+
if base.Proxy == "" {
43+
return http.ProxyFromEnvironment(request)
44+
}
45+
return url.Parse(base.Proxy)
46+
},
47+
ForceAttemptHTTP2: true,
3448
MaxIdleConnsPerHost: 999,
3549
},
3650
Timeout: time.Second * 5,
@@ -42,11 +56,13 @@ var ErrOverSize = errors.New("oversize")
4256
// UserAgent HTTP请求时使用的UA
4357
const UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66"
4458

45-
func SetGlobalTimeout(t time.Duration) {
59+
// SetTimeout set internal/download client timeout
60+
func SetTimeout(t time.Duration) {
4661
if t == 0 {
4762
t = time.Second * 10
4863
}
4964
client.Timeout = t
65+
clienth2.Timeout = t
5066
}
5167

5268
// Request is a file download request
@@ -58,6 +74,13 @@ type Request struct {
5874
Body io.Reader
5975
}
6076

77+
func (r Request) client() *http.Client {
78+
if strings.Contains(r.URL, "go-cqhttp.org") {
79+
return clienth2
80+
}
81+
return client
82+
}
83+
6184
func (r Request) do() (*http.Response, error) {
6285
if r.Method == "" {
6386
r.Method = http.MethodGet
@@ -72,7 +95,7 @@ func (r Request) do() (*http.Response, error) {
7295
req.Header.Set(k, v)
7396
}
7497

75-
return client.Do(req)
98+
return r.client().Do(req)
7699
}
77100

78101
func (r Request) body() (io.ReadCloser, error) {

‎internal/encryption/t544/encryption.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func sub_e(*[256][6]byte, []byte)
4444
//go:noescape
4545
func sub_f(*[16]byte, *[15]uint32, *[16][16]byte) (w [44]uint32)
4646

47+
//go:noescape
4748
func sub_aa(int, *[16][2][16][16]byte, *[16]byte, []byte) byte
4849

4950
// transformInner see com/tencent/mobileqq/dt/model/FEBound

‎pkg/onebot/value.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type (
3131
// Kind is the kind of Value.
3232
type Kind int
3333

34+
// Kind
3435
const (
3536
KindAny Kind = iota
3637
KindBool

0 commit comments

Comments
 (0)