mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-05-13 13:38:06 +08:00
fix: don't ignore http.NewRequest's error
This commit is contained in:
parent
1bc3c16b59
commit
87877d1b80
@ -139,7 +139,10 @@ func realityClientFallback(uConn net.Conn, serverName string, fingerprint utls.C
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
request, _ := http.NewRequest("GET", "https://"+serverName, nil)
|
request, err := http.NewRequest("GET", "https://"+serverName, nil)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
request.Header.Set("User-Agent", fingerprint.Client)
|
request.Header.Set("User-Agent", fingerprint.Client)
|
||||||
request.AddCookie(&http.Cookie{Name: "padding", Value: strings.Repeat("0", fastrand.Intn(32)+30)})
|
request.AddCookie(&http.Cookie{Name: "padding", Value: strings.Repeat("0", fastrand.Intn(32)+30)})
|
||||||
response, err := client.Do(request)
|
response, err := client.Do(request)
|
||||||
|
@ -65,7 +65,10 @@ func (ho *HTTPObfs) Write(b []byte) (int, error) {
|
|||||||
if ho.firstRequest {
|
if ho.firstRequest {
|
||||||
randBytes := make([]byte, 16)
|
randBytes := make([]byte, 16)
|
||||||
fastrand.Read(randBytes)
|
fastrand.Read(randBytes)
|
||||||
req, _ := http.NewRequest("GET", fmt.Sprintf("http://%s/", ho.host), bytes.NewBuffer(b[:]))
|
req, err := http.NewRequest("GET", fmt.Sprintf("http://%s/", ho.host), bytes.NewBuffer(b[:]))
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
req.Header.Set("User-Agent", fmt.Sprintf("curl/7.%d.%d", fastrand.Int()%54, fastrand.Int()%2))
|
req.Header.Set("User-Agent", fmt.Sprintf("curl/7.%d.%d", fastrand.Int()%54, fastrand.Int()%2))
|
||||||
req.Header.Set("Upgrade", "websocket")
|
req.Header.Set("Upgrade", "websocket")
|
||||||
req.Header.Set("Connection", "Upgrade")
|
req.Header.Set("Connection", "Upgrade")
|
||||||
@ -75,7 +78,7 @@ func (ho *HTTPObfs) Write(b []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
req.Header.Set("Sec-WebSocket-Key", base64.URLEncoding.EncodeToString(randBytes))
|
req.Header.Set("Sec-WebSocket-Key", base64.URLEncoding.EncodeToString(randBytes))
|
||||||
req.ContentLength = int64(len(b))
|
req.ContentLength = int64(len(b))
|
||||||
err := req.Write(ho.Conn)
|
err = req.Write(ho.Conn)
|
||||||
ho.firstRequest = false
|
ho.firstRequest = false
|
||||||
return len(b), err
|
return len(b), err
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,10 @@ func (hc *httpConn) Write(b []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
u := fmt.Sprintf("http://%s%s", net.JoinHostPort(host, "80"), path)
|
u := fmt.Sprintf("http://%s%s", net.JoinHostPort(host, "80"), path)
|
||||||
req, _ := http.NewRequest(utils.EmptyOr(hc.cfg.Method, http.MethodGet), u, bytes.NewBuffer(b))
|
req, err := http.NewRequest(utils.EmptyOr(hc.cfg.Method, http.MethodGet), u, bytes.NewBuffer(b))
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
for key, list := range hc.cfg.Headers {
|
for key, list := range hc.cfg.Headers {
|
||||||
req.Header.Set(key, list[fastrand.Intn(len(list))])
|
req.Header.Set(key, list[fastrand.Intn(len(list))])
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user