forked from aurora-develop/aurora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
49 lines (45 loc) · 1.36 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package httpclient
import (
"aurora/util"
"crypto/tls"
browser "github.com/EDDYCJY/fake-useragent"
"github.com/go-resty/resty/v2"
"net/http"
"time"
)
type RestyClient struct {
Client *resty.Client
}
func NewStdClient() *RestyClient {
client := &RestyClient{
Client: resty.NewWithClient(&http.Client{
Transport: &http.Transport{
// 禁用长连接
DisableKeepAlives: true,
// 配置TLS设置,跳过证书验证
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
}),
}
client.Client.SetBaseURL("https://chat.openai.com")
client.Client.SetRetryCount(3)
client.Client.SetRetryWaitTime(5 * time.Second)
client.Client.SetRetryMaxWaitTime(20 * time.Second)
client.Client.SetTimeout(600 * time.Second)
client.Client.SetHeader("user-agent", browser.Random()).
SetHeader("accept", "*/*").
SetHeader("accept-language", "en-US,en;q=0.9").
SetHeader("cache-control", "no-cache").
SetHeader("content-type", "application/json").
SetHeader("oai-language", util.RandomLanguage()).
SetHeader("pragma", "no-cache").
SetHeader("sec-ch-ua", `"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"`).
SetHeader("sec-ch-ua-mobile", "?0").
SetHeader("sec-ch-ua-platform", "Windows").
SetHeader("sec-fetch-dest", "empty").
SetHeader("sec-fetch-mode", "cors").
SetHeader("sec-fetch-site", "same-origin")
return client
}