未传入User-Agent时设置默认值

This commit is contained in:
白茶清欢 2025-04-16 21:05:23 +08:00
parent 60dd279663
commit 834ce55f26

View File

@ -75,6 +75,12 @@ func NewHttpClient(reqConfig *define.Request, cacheInstance cache.ICache) (*Http
} }
} }
} }
if reqConfig.Header == nil {
reqConfig.Header = make(map[string]any)
}
if ua, exist := reqConfig.Header[consts.HeaderKeyUserAgent.String()]; !exist || nil == ua || fmt.Sprintf("%v", ua) == "" {
reqConfig.Header[consts.HeaderKeyUserAgent.String()] = "resty-v2@network/httpclient"
}
restyClient, restyRequest := NewRestyClient(reqConfig) restyClient, restyRequest := NewRestyClient(reqConfig)
hc := &HttpClient{ hc := &HttpClient{
Client: restyClient, Client: restyClient,