use sync.Once

This commit is contained in:
Doğan Can Bakır 2024-08-21 11:26:17 +03:00
parent 50023428d0
commit 46782ff90c

View File

@ -29,10 +29,10 @@ import (
var (
rawHttpClient *rawhttp.Client
rawHttpClientOnce sync.Once
forceMaxRedirects int
normalClient *retryablehttp.Client
clientPool *mapsutil.SyncLockMap[string, *retryablehttp.Client]
rawHttpClientMu sync.Mutex
)
// Init initializes the clientpool implementation
@ -148,10 +148,7 @@ func (c *Configuration) HasStandardOptions() bool {
// GetRawHTTP returns the rawhttp request client
func GetRawHTTP(options *protocols.ExecutorOptions) *rawhttp.Client {
rawHttpClientMu.Lock()
defer rawHttpClientMu.Unlock()
if rawHttpClient == nil {
rawHttpClientOnce.Do(func() {
rawHttpOptions := rawhttp.DefaultOptions
if types.ProxyURL != "" {
rawHttpOptions.Proxy = types.ProxyURL
@ -162,7 +159,7 @@ func GetRawHTTP(options *protocols.ExecutorOptions) *rawhttp.Client {
}
rawHttpOptions.Timeout = options.Options.GetTimeouts().HttpTimeout
rawHttpClient = rawhttp.NewClient(rawHttpOptions)
}
})
return rawHttpClient
}