@@ -76,6 +76,7 @@ type AppsecSource struct {
76
76
appsecAllowlistClient * allowlists.AppsecAllowlist
77
77
lapiCACertPool * x509.CertPool
78
78
authMutex sync.Mutex
79
+ httpClient * http.Client
79
80
}
80
81
81
82
// Struct to handle cache of authentication
@@ -306,6 +307,17 @@ func (w *AppsecSource) Configure(yamlConfig []byte, logger *log.Entry, metricsLe
306
307
return fmt .Errorf ("unable to load LAPI CA cert pool: %w" , err )
307
308
}
308
309
310
+ w .httpClient = & http.Client {
311
+ Timeout : 200 * time .Millisecond ,
312
+ }
313
+ if w .lapiCACertPool != nil {
314
+ w .httpClient .Transport = & http.Transport {
315
+ TLSClientConfig : & tls.Config {
316
+ RootCAs : w .lapiCACertPool ,
317
+ },
318
+ }
319
+ }
320
+
309
321
return nil
310
322
}
311
323
@@ -477,19 +489,7 @@ func (w *AppsecSource) isValidKey(ctx context.Context, apiKey string) (bool, err
477
489
req .Header .Add ("X-Api-Key" , apiKey )
478
490
req .Header .Add ("User-Agent" , useragent .AppsecUserAgent ())
479
491
480
- client := & http.Client {
481
- Timeout : 200 * time .Millisecond ,
482
- }
483
-
484
- if w .lapiCACertPool != nil {
485
- client .Transport = & http.Transport {
486
- TLSClientConfig : & tls.Config {
487
- RootCAs : w .lapiCACertPool ,
488
- },
489
- }
490
- }
491
-
492
- resp , err := client .Do (req )
492
+ resp , err := w .httpClient .Do (req )
493
493
if err != nil {
494
494
w .logger .Errorf ("Error performing request: %s" , err )
495
495
return false , err
0 commit comments