4
4
"adams549659584/go-proxy-bingai/api/helper"
5
5
"adams549659584/go-proxy-bingai/common"
6
6
"encoding/json"
7
- "fmt"
8
7
"net/http"
9
8
"net/url"
10
9
"strings"
@@ -14,6 +13,8 @@ import (
14
13
binglib "github.com/Harry-zklcdc/bing-lib"
15
14
)
16
15
16
+ var removeCookieName = []string {common .USER_TOKEN_COOKIE_NAME , common .USER_KievRPSSecAuth_COOKIE_NAME , common .USER_RwBf_COOKIE_NAME , common .PASS_SERVER_COOKIE_NAME , common .RAND_COOKIE_INDEX_NAME }
17
+
17
18
func VerifyHandler (w http.ResponseWriter , r * http.Request ) {
18
19
if ! helper .CheckAuth (r ) {
19
20
helper .UnauthorizedResult (w )
@@ -30,7 +31,6 @@ func VerifyHandler(w http.ResponseWriter, r *http.Request) {
30
31
T , _ := url .QueryUnescape (r .URL .Query ().Get ("T" ))
31
32
token , err := aes .Decrypt (T , IG )
32
33
if err != nil {
33
- fmt .Println (err )
34
34
helper .ErrorResult (w , http .StatusInternalServerError , "Server Error" )
35
35
return
36
36
}
@@ -39,21 +39,27 @@ func VerifyHandler(w http.ResponseWriter, r *http.Request) {
39
39
return
40
40
}
41
41
42
- reqCookies := strings .Split (r .Header .Get ("Cookie" ), "; " )
43
42
bypassServer := common .BypassServer
44
- for _ , cookie := range reqCookies {
45
- if strings .HasPrefix (cookie , "BingAI_Pass_Server" ) {
46
- tmp := strings .ReplaceAll (cookie , "BingAI_Pass_Server=" , "" )
47
- if tmp != "" {
48
- bypassServer = tmp
49
- }
43
+
44
+ header := http.Header {}
45
+ header .Add ("Cookie" , r .Header .Get ("Cookie" ))
46
+ req := & http.Request {
47
+ Header : header ,
48
+ }
49
+ if cookie , err := req .Cookie (common .PASS_SERVER_COOKIE_NAME ); err == nil {
50
+ bypassServer = cookie .Value
51
+ }
52
+ reqCookies := []string {}
53
+ for _ , cookie := range req .Cookies () {
54
+ if ! common .IsInArray (removeCookieName , cookie .Name ) {
55
+ reqCookies = append (reqCookies , cookie .String ())
50
56
}
51
57
}
52
58
53
59
iframeid , _ := url .QueryUnescape (queryRaw .Get ("iframeid" ))
54
60
convId , _ := url .QueryUnescape (queryRaw .Get ("convId" ))
55
61
rid , _ := url .QueryUnescape (queryRaw .Get ("rid" ))
56
- resp , status , err := binglib .Bypass (bypassServer , r . Header . Get ( "Cookie " ), iframeid , IG , convId , rid , T )
62
+ resp , status , err := binglib .Bypass (bypassServer , strings . Join ( reqCookies , "; " ), iframeid , IG , convId , rid , T )
57
63
if err != nil {
58
64
helper .ErrorResult (w , http .StatusInternalServerError , err .Error ())
59
65
return
@@ -70,7 +76,9 @@ func VerifyHandler(w http.ResponseWriter, r *http.Request) {
70
76
71
77
cookies := strings .Split (resp .Result .Cookies , "; " )
72
78
for _ , cookie := range cookies {
73
- w .Header ().Add ("Set-Cookie" , cookie + "; path=/" )
79
+ if ! common .IsInArray (removeCookieName , strings .Split (cookie , "=" )[0 ]) {
80
+ w .Header ().Add ("Set-Cookie" , cookie + "; path=/" )
81
+ }
74
82
}
75
83
76
84
helper .CommonResult (w , http .StatusOK , "ok" , resp )
0 commit comments