Skip to content

Commit

Permalink
feat: http timeout setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrs4s committed Apr 8, 2023
1 parent 55cb80d commit 0b90074
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/gocq/main.go
Expand Up @@ -364,6 +364,7 @@ func LoginInteract() {
})
saveToken()
cli.AllowSlider = true
download.SetGlobalTimeout(time.Duration(base.HTTPTimeout) * time.Second) // 在登录完成后设置, 防止在堵塞协议更新
log.Infof("登录成功 欢迎使用: %v", cli.Nickname)
log.Info("开始加载好友列表...")
global.Check(cli.ReloadFriendList(), true)
Expand All @@ -375,7 +376,6 @@ func LoginInteract() {
base.Account.Status = 0
}
cli.SetOnlineStatus(allowStatus[base.Account.Status])

servers.Run(coolq.NewQQBot(cli))
log.Info("资源初始化完成, 开始处理信息.")
log.Info("アトリは、高性能ですから!")
Expand Down
2 changes: 2 additions & 0 deletions internal/base/flag.go
Expand Up @@ -39,6 +39,7 @@ var (
AllowTempSession bool // 是否允许发送临时会话信息
UpdateProtocol bool // 是否更新协议
SignServerOverwrite string // 使用特定的服务器进行签名
HTTPTimeout int

PostFormat string // 上报格式 string or array
Proxy string // 存储 proxy_rewrite,用于设置代理
Expand Down Expand Up @@ -88,6 +89,7 @@ func Init() {
ReportSelfMessage = conf.Message.ReportSelfMessage
UseSSOAddress = conf.Account.UseSSOAddress
AllowTempSession = conf.Account.AllowTempSession
HTTPTimeout = conf.Message.HTTPTimeout
}
{ // others
Proxy = conf.Message.ProxyRewrite
Expand Down
9 changes: 8 additions & 1 deletion internal/download/download.go
Expand Up @@ -33,7 +33,7 @@ var client = &http.Client{
MaxIdleConns: 0,
MaxIdleConnsPerHost: 999,
},
Timeout: time.Second * 15,
Timeout: time.Second * 5,
}

// ErrOverSize 响应主体过大时返回此错误
Expand All @@ -42,6 +42,13 @@ var ErrOverSize = errors.New("oversize")
// 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"

func SetGlobalTimeout(t time.Duration) {

Check warning on line 45 in internal/download/download.go

View workflow job for this annotation

GitHub Actions / lint

exported: exported function SetGlobalTimeout should have comment or be unexported (revive)
if t == 0 {
t = time.Second * 10
}
client.Timeout = t
}

// Request is a file download request
type Request struct {
Method string
Expand Down
1 change: 1 addition & 0 deletions modules/config/config.go
Expand Up @@ -56,6 +56,7 @@ type Config struct {
ExtraReplyData bool `yaml:"extra-reply-data"`
SkipMimeScan bool `yaml:"skip-mime-scan"`
ConvertWebpImage bool `yaml:"convert-webp-image"`
HTTPTimeout int `yaml:"http-timeout"`
} `yaml:"message"`

Output struct {
Expand Down

1 comment on commit 0b90074

@Janet-Baker
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

默认配置文件 modules/config/default_config.yml 没有添加 http-timeout 一项。

Please sign in to comment.