sanbo1200 commited on
Commit
01a7d37
·
verified ·
1 Parent(s): 0dd2e49

Delete httpclient

Browse files
httpclient/Iaurorahttpclient.go DELETED
@@ -1,28 +0,0 @@
1
- package httpclient
2
-
3
- import (
4
- "io"
5
- "net/http"
6
- )
7
-
8
- type AuroraHttpClient interface {
9
- Request(method HttpMethod, url string, headers AuroraHeaders, cookies []*http.Cookie, body io.Reader) (*http.Response, error)
10
- SetProxy(url string) error
11
- }
12
-
13
- type HttpMethod string
14
-
15
- const (
16
- GET HttpMethod = "GET"
17
- POST HttpMethod = "POST"
18
- PUT HttpMethod = "PUT"
19
- HEAD HttpMethod = "HEAD"
20
- DELETE HttpMethod = "DELETE"
21
- OPTIONS HttpMethod = "OPTIONS"
22
- )
23
-
24
- type AuroraHeaders map[string]string
25
-
26
- func (a AuroraHeaders) Set(key, value string) {
27
- a[key] = value
28
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
httpclient/bogdanfinn/tls_client.go DELETED
@@ -1,102 +0,0 @@
1
- package bogdanfinn
2
-
3
- import (
4
- "aurora/httpclient"
5
- "io"
6
- "net/http"
7
-
8
- fhttp "github.com/bogdanfinn/fhttp"
9
- tls_client "github.com/bogdanfinn/tls-client"
10
- "github.com/bogdanfinn/tls-client/profiles"
11
- )
12
-
13
- type TlsClient struct {
14
- Client tls_client.HttpClient
15
- ReqBefore handler
16
- }
17
-
18
- type handler func(r *fhttp.Request) error
19
-
20
- func NewStdClient() *TlsClient {
21
- client, _ := tls_client.NewHttpClient(tls_client.NewNoopLogger(), []tls_client.HttpClientOption{
22
- tls_client.WithCookieJar(tls_client.NewCookieJar()),
23
- tls_client.WithRandomTLSExtensionOrder(),
24
- tls_client.WithTimeoutSeconds(600),
25
- tls_client.WithClientProfile(profiles.Okhttp4Android13),
26
- }...)
27
-
28
- stdClient := &TlsClient{Client: client}
29
- return stdClient
30
- }
31
-
32
- func convertResponse(resp *fhttp.Response) *http.Response {
33
- response := &http.Response{
34
- Status: resp.Status,
35
- StatusCode: resp.StatusCode,
36
- Proto: resp.Proto,
37
- ProtoMajor: resp.ProtoMajor,
38
- ProtoMinor: resp.ProtoMinor,
39
- Header: http.Header(resp.Header),
40
- Body: resp.Body,
41
- ContentLength: resp.ContentLength,
42
- TransferEncoding: resp.TransferEncoding,
43
- Close: resp.Close,
44
- Uncompressed: resp.Uncompressed,
45
- Trailer: http.Header(resp.Trailer),
46
- }
47
- return response
48
- }
49
-
50
- func (t *TlsClient) handleHeaders(req *fhttp.Request, headers httpclient.AuroraHeaders) {
51
- if headers == nil {
52
- return
53
- }
54
- for k, v := range headers {
55
- req.Header.Set(k, v)
56
- }
57
- }
58
-
59
- func (t *TlsClient) handleCookies(req *fhttp.Request, cookies []*http.Cookie) {
60
- if cookies == nil {
61
- return
62
- }
63
- for _, c := range cookies {
64
- req.AddCookie(&fhttp.Cookie{
65
- Name: c.Name,
66
- Value: c.Value,
67
- Path: c.Path,
68
- Domain: c.Domain,
69
- Expires: c.Expires,
70
- RawExpires: c.RawExpires,
71
- MaxAge: c.MaxAge,
72
- Secure: c.Secure,
73
- HttpOnly: c.HttpOnly,
74
- SameSite: fhttp.SameSite(c.SameSite),
75
- Raw: c.Raw,
76
- Unparsed: c.Unparsed,
77
- })
78
- }
79
- }
80
-
81
- func (t *TlsClient) Request(method httpclient.HttpMethod, url string, headers httpclient.AuroraHeaders, cookies []*http.Cookie, body io.Reader) (*http.Response, error) {
82
- req, err := fhttp.NewRequest(string(method), url, body)
83
- if err != nil {
84
- return nil, err
85
- }
86
- t.handleHeaders(req, headers)
87
- t.handleCookies(req, cookies)
88
- if t.ReqBefore != nil {
89
- if err := t.ReqBefore(req); err != nil {
90
- return nil, err
91
- }
92
- }
93
- do, err := t.Client.Do(req)
94
- if err != nil {
95
- return nil, err
96
- }
97
- return convertResponse(do), nil
98
- }
99
-
100
- func (t *TlsClient) SetProxy(url string) error {
101
- return t.Client.SetProxy(url)
102
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
httpclient/bogdanfinn/tls_client_test.go DELETED
@@ -1,101 +0,0 @@
1
- package bogdanfinn
2
-
3
- import (
4
- "aurora/httpclient"
5
- "fmt"
6
- "io"
7
- "net/http"
8
- "os"
9
- "strings"
10
- "testing"
11
-
12
- "github.com/joho/godotenv"
13
- )
14
-
15
- var BaseURL string
16
-
17
- func init() {
18
- _ = godotenv.Load(".env")
19
- BaseURL = os.Getenv("BASE_URL")
20
- if BaseURL == "" {
21
- BaseURL = "https://chat.openai.com/backend-anon"
22
- }
23
- }
24
- func TestTlsClient_Request(t *testing.T) {
25
- client := NewStdClient()
26
- userAgent := "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"
27
- proxy := "http://127.0.0.1:7990"
28
- client.SetProxy(proxy)
29
-
30
- apiUrl := BaseURL + "/sentinel/chat-requirements"
31
- payload := strings.NewReader(`{"conversation_mode_kind":"primary_assistant"}`)
32
- header := make(httpclient.AuroraHeaders)
33
- header.Set("Content-Type", "application/json")
34
- header.Set("User-Agent", userAgent)
35
- header.Set("Accept", "*/*")
36
- header.Set("oai-language", "en-US")
37
- header.Set("origin", "https://chat.openai.com")
38
- header.Set("referer", "https://chat.openai.com/")
39
- header.Set("oai-device-id", "c83b24f0-5a9e-4c43-8915-3f67d4332609")
40
- response, err := client.Request(http.MethodPost, apiUrl, header, nil, payload)
41
- if err != nil {
42
- return
43
- }
44
- defer response.Body.Close()
45
- fmt.Println(response.StatusCode)
46
- if response.StatusCode != 200 {
47
- fmt.Println("Error: ", response.StatusCode)
48
- }
49
- }
50
-
51
- func TestChatGPTModel(t *testing.T) {
52
- client := NewStdClient()
53
- userAgent := "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"
54
- proxy := "http://127.0.0.1:7990"
55
- client.SetProxy(proxy)
56
- apiUrl := "https://chat.openai.com/backend-anon/models"
57
-
58
- header := make(httpclient.AuroraHeaders)
59
- header.Set("Content-Type", "application/json")
60
- header.Set("User-Agent", userAgent)
61
- header.Set("Accept", "*/*")
62
- header.Set("oai-language", "en-US")
63
- header.Set("origin", "https://chat.openai.com")
64
- header.Set("referer", "https://chat.openai.com/")
65
- header.Set("oai-device-id", "c83b24f0-5a9e-4c43-8915-3f67d4332609")
66
- response, err := client.Request(http.MethodGet, apiUrl, header, nil, nil)
67
- if err != nil {
68
- return
69
- }
70
- defer response.Body.Close()
71
- fmt.Println(response.StatusCode)
72
- if response.StatusCode != 200 {
73
- fmt.Println("Error: ", response.StatusCode)
74
- body, _ := io.ReadAll(response.Body)
75
- fmt.Println(string(body))
76
- return
77
- }
78
-
79
- type EnginesData struct {
80
- Models []struct {
81
- Slug string `json:"slug"`
82
- MaxTokens int `json:"max_tokens"`
83
- Title string `json:"title"`
84
- Description string `json:"description"`
85
- Tags []string `json:"tags"`
86
- Capabilities struct {
87
- } `json:"capabilities,omitempty"`
88
- ProductFeatures struct {
89
- } `json:"product_features,omitempty"`
90
- } `json:"models"`
91
- Categories []struct {
92
- Category string `json:"category"`
93
- HumanCategoryName string `json:"human_category_name"`
94
- SubscriptionLevel string `json:"subscription_level"`
95
- DefaultModel string `json:"default_model"`
96
- CodeInterpreterModel string `json:"code_interpreter_model,omitempty"`
97
- PluginsModel string `json:"plugins_model"`
98
- } `json:"categories"`
99
- }
100
-
101
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
httpclient/resty/resty_client.go DELETED
@@ -1,72 +0,0 @@
1
- package resty
2
-
3
- import (
4
- "aurora/util"
5
- "crypto/tls"
6
- browser "github.com/EDDYCJY/fake-useragent"
7
- "github.com/go-resty/resty/v2"
8
- "net/http"
9
- "time"
10
- )
11
-
12
- type RestyClient struct {
13
- Client *resty.Client
14
- }
15
-
16
- func NewStdClient() *RestyClient {
17
- client := &RestyClient{
18
- Client: resty.NewWithClient(&http.Client{
19
- Transport: &http.Transport{
20
- // 禁用长连接
21
- DisableKeepAlives: true,
22
- // 配置TLS设置,跳过证书验证
23
- TLSClientConfig: &tls.Config{
24
- InsecureSkipVerify: true,
25
- },
26
- },
27
- }),
28
- }
29
- client.Client.SetBaseURL("https://chat.openai.com")
30
- client.Client.SetRetryCount(3)
31
- client.Client.SetRetryWaitTime(5 * time.Second)
32
- client.Client.SetRetryMaxWaitTime(20 * time.Second)
33
-
34
- client.Client.SetTimeout(600 * time.Second)
35
- client.Client.SetHeader("user-agent", browser.Random()).
36
- SetHeader("accept", "*/*").
37
- SetHeader("accept-language", "en-US,en;q=0.9").
38
- SetHeader("cache-control", "no-cache").
39
- SetHeader("content-type", "application/json").
40
- SetHeader("oai-language", util.RandomLanguage()).
41
- SetHeader("pragma", "no-cache").
42
- SetHeader("sec-ch-ua", `"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"`).
43
- SetHeader("sec-ch-ua-mobile", "?0").
44
- SetHeader("sec-ch-ua-platform", "Windows").
45
- SetHeader("sec-fetch-dest", "empty").
46
- SetHeader("sec-fetch-mode", "cors").
47
- SetHeader("sec-fetch-site", "same-origin")
48
- return client
49
- }
50
-
51
- //func (c *RestyClient) Request(method string, url string, headers map[string]string, cookies []*http.Cookie, body io.Reader) (*http.Response, error) {
52
- //}
53
-
54
- //func (c *RestyClient) Post(url string, headers map[string]string, cookies []*http.Cookie, body io.Reader) (*http.Response, error) {
55
- //}
56
- //
57
- //func (c *RestyClient) Get(url string, headers map[string]string, cookies []*http.Cookie, body io.Reader) (*http.Response, error) {
58
- //}
59
- //
60
- //func (c *RestyClient) Head(url string, headers map[string]string, cookies []*http.Cookie, body io.Reader) (*http.Response, error) {
61
- //}
62
- //
63
- //func (c *RestyClient) Options(url string, headers map[string]string, cookies []*http.Cookie, body io.Reader) (*http.Response, error) {
64
- //}
65
- //
66
- //func (c *RestyClient) Put(url string, headers map[string]string, cookies []*http.Cookie, body io.Reader) (*http.Response, error) {
67
- //}
68
- //
69
- //func (c *RestyClient) Delete(url string, headers map[string]string, cookies []*http.Cookie, body io.Reader) (*http.Response, error) {
70
- //}
71
- //
72
- //func (c *RestyClient) SetProxy(url string) error {}