From 696f68088b8c30dfaf83050890281899784cab8b Mon Sep 17 00:00:00 2001 From: zema1 Date: Mon, 20 Nov 2023 18:22:41 +0800 Subject: [PATCH] feat: remove some traits --- ctrl/config.go | 22 ++++++++++++++++++++++ ctrl/ctrl.go | 8 ++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/ctrl/config.go b/ctrl/config.go index 62e3f48..c92a69b 100644 --- a/ctrl/config.go +++ b/ctrl/config.go @@ -45,6 +45,28 @@ func (s *Suo5Config) parseHeader() error { } s.Header.Set(strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1])) } + + if s.Header.Get("Cache-Control") == "" { + s.Header.Set("Cache-Control", "no-cache") + } + if s.Header.Get("Pragma") == "" { + s.Header.Set("Pragma", "no-cache") + } + if s.Header.Get("Referer") == "" { + n := strings.LastIndex(s.Target, "/") + if n == -1 { + s.Header.Set("Referer", s.Target) + } else { + s.Header.Set("Referer", s.Target[:n+1]) + } + } + if s.Header.Get("Accept") == "" { + s.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7") + } + if s.Header.Get("Accept-Language") == "" { + s.Header.Set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6") + } + return nil } diff --git a/ctrl/ctrl.go b/ctrl/ctrl.go index 2c0a075..705e85b 100644 --- a/ctrl/ctrl.go +++ b/ctrl/ctrl.go @@ -203,7 +203,11 @@ func Run(ctx context.Context, config *Suo5Config) error { func checkConnectMode(method string, target string, baseHeader http.Header, proxy string) (ConnectionType, int, error) { // 这里的 client 需要定义 timeout,不要用外面没有 timeout 的 rawCient rawClient := newRawClient(proxy, time.Second*5) - data := RandString(32) + randLen := rand.Intn(1024) + if randLen <= 32 { + randLen += 32 + } + data := RandString(randLen) ch := make(chan []byte, 1) ch <- []byte(data) req, err := http.NewRequest(method, target, netrans.NewChannelReader(ch)) @@ -233,7 +237,7 @@ func checkConnectMode(method string, target string, baseHeader http.Header, prox } duration := time.Since(now).Milliseconds() - offset := strings.Index(string(body), data) + offset := strings.Index(string(body), data[:32]) if offset == -1 { header, _ := httputil.DumpResponse(resp, false) log.Errorf("response are as follows:\n%s", string(header)+string(body))