chore: refine code

This commit is contained in:
MetaCubeX
2022-06-08 01:47:50 +08:00
parent ed17a1bf23
commit 9511ccfe47
4 changed files with 34 additions and 20 deletions

View File

@ -291,7 +291,7 @@ var (
)
func RandHost() string {
id, _ := uuid.NewV6()
id, _ := uuid.NewV4()
base := strings.ToLower(base64.RawURLEncoding.EncodeToString(id.Bytes()))
base = strings.ReplaceAll(base, "-", "")
base = strings.ReplaceAll(base, "_", "")
@ -307,7 +307,10 @@ func RandUserAgent() string {
return userAgents[rand.Intn(uaLen)]
}
func SetUserAgent(req *http.Request) {
func SetUserAgent(header http.Header) {
if header.Get("User-Agent") != "" {
return
}
userAgent := RandUserAgent()
req.Header.Set("User-Agent", userAgent)
header.Set("User-Agent", userAgent)
}