Skip to content

Commit

Permalink
feat: remove some traits
Browse files Browse the repository at this point in the history
  • Loading branch information
zema1 committed Nov 20, 2023
1 parent f9d159a commit 696f680
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
22 changes: 22 additions & 0 deletions ctrl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 6 additions & 2 deletions ctrl/ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 696f680

Please sign in to comment.