mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-04 19:17:37 +08:00
internal/download: disable http when not visiting go-cqhttp.org
This commit is contained in:
parent
1ed675d5bf
commit
42606a825d
@ -364,7 +364,7 @@ func LoginInteract() {
|
|||||||
})
|
})
|
||||||
saveToken()
|
saveToken()
|
||||||
cli.AllowSlider = true
|
cli.AllowSlider = true
|
||||||
download.SetGlobalTimeout(time.Duration(base.HTTPTimeout) * time.Second) // 在登录完成后设置, 防止在堵塞协议更新
|
download.SetTimeout(time.Duration(base.HTTPTimeout) * time.Second) // 在登录完成后设置, 防止在堵塞协议更新
|
||||||
log.Infof("登录成功 欢迎使用: %v", cli.Nickname)
|
log.Infof("登录成功 欢迎使用: %v", cli.Nickname)
|
||||||
log.Info("开始加载好友列表...")
|
log.Info("开始加载好友列表...")
|
||||||
global.Check(cli.ReloadFriendList(), true)
|
global.Check(cli.ReloadFriendList(), true)
|
||||||
|
@ -4,6 +4,7 @@ package download
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -22,15 +23,28 @@ import (
|
|||||||
|
|
||||||
var client = &http.Client{
|
var client = &http.Client{
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
Proxy: func(request *http.Request) (u *url.URL, e error) {
|
Proxy: func(request *http.Request) (*url.URL, error) {
|
||||||
if base.Proxy == "" {
|
if base.Proxy == "" {
|
||||||
return http.ProxyFromEnvironment(request)
|
return http.ProxyFromEnvironment(request)
|
||||||
}
|
}
|
||||||
return url.Parse(base.Proxy)
|
return url.Parse(base.Proxy)
|
||||||
},
|
},
|
||||||
ForceAttemptHTTP2: false,
|
// Disable http2
|
||||||
MaxConnsPerHost: 0,
|
TLSNextProto: map[string]func(authority string, c *tls.Conn) http.RoundTripper{},
|
||||||
MaxIdleConns: 0,
|
MaxIdleConnsPerHost: 999,
|
||||||
|
},
|
||||||
|
Timeout: time.Second * 5,
|
||||||
|
}
|
||||||
|
|
||||||
|
var clienth2 = &http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
Proxy: func(request *http.Request) (*url.URL, error) {
|
||||||
|
if base.Proxy == "" {
|
||||||
|
return http.ProxyFromEnvironment(request)
|
||||||
|
}
|
||||||
|
return url.Parse(base.Proxy)
|
||||||
|
},
|
||||||
|
ForceAttemptHTTP2: true,
|
||||||
MaxIdleConnsPerHost: 999,
|
MaxIdleConnsPerHost: 999,
|
||||||
},
|
},
|
||||||
Timeout: time.Second * 5,
|
Timeout: time.Second * 5,
|
||||||
@ -42,11 +56,13 @@ var ErrOverSize = errors.New("oversize")
|
|||||||
// UserAgent HTTP请求时使用的UA
|
// UserAgent HTTP请求时使用的UA
|
||||||
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"
|
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"
|
||||||
|
|
||||||
func SetGlobalTimeout(t time.Duration) {
|
// SetTimeout set internal/download client timeout
|
||||||
|
func SetTimeout(t time.Duration) {
|
||||||
if t == 0 {
|
if t == 0 {
|
||||||
t = time.Second * 10
|
t = time.Second * 10
|
||||||
}
|
}
|
||||||
client.Timeout = t
|
client.Timeout = t
|
||||||
|
clienth2.Timeout = t
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request is a file download request
|
// Request is a file download request
|
||||||
@ -58,6 +74,13 @@ type Request struct {
|
|||||||
Body io.Reader
|
Body io.Reader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r Request) client() *http.Client {
|
||||||
|
if strings.Contains(r.URL, "go-cqhttp.org") {
|
||||||
|
return clienth2
|
||||||
|
}
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
func (r Request) do() (*http.Response, error) {
|
func (r Request) do() (*http.Response, error) {
|
||||||
if r.Method == "" {
|
if r.Method == "" {
|
||||||
r.Method = http.MethodGet
|
r.Method = http.MethodGet
|
||||||
@ -72,7 +95,7 @@ func (r Request) do() (*http.Response, error) {
|
|||||||
req.Header.Set(k, v)
|
req.Header.Set(k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
return client.Do(req)
|
return r.client().Do(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Request) body() (io.ReadCloser, error) {
|
func (r Request) body() (io.ReadCloser, error) {
|
||||||
|
@ -44,6 +44,7 @@ func sub_e(*[256][6]byte, []byte)
|
|||||||
//go:noescape
|
//go:noescape
|
||||||
func sub_f(*[16]byte, *[15]uint32, *[16][16]byte) (w [44]uint32)
|
func sub_f(*[16]byte, *[15]uint32, *[16][16]byte) (w [44]uint32)
|
||||||
|
|
||||||
|
//go:noescape
|
||||||
func sub_aa(int, *[16][2][16][16]byte, *[16]byte, []byte) byte
|
func sub_aa(int, *[16][2][16][16]byte, *[16]byte, []byte) byte
|
||||||
|
|
||||||
// transformInner see com/tencent/mobileqq/dt/model/FEBound
|
// transformInner see com/tencent/mobileqq/dt/model/FEBound
|
||||||
|
@ -31,6 +31,7 @@ type (
|
|||||||
// Kind is the kind of Value.
|
// Kind is the kind of Value.
|
||||||
type Kind int
|
type Kind int
|
||||||
|
|
||||||
|
// Kind
|
||||||
const (
|
const (
|
||||||
KindAny Kind = iota
|
KindAny Kind = iota
|
||||||
KindBool
|
KindBool
|
||||||
|
Loading…
x
Reference in New Issue
Block a user