Skip to content

Commit 88e3b9b

Browse files
enhance: appsec reuse httpc optimization (#3693)
1 parent b5d90ff commit 88e3b9b

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

pkg/acquisition/modules/appsec/appsec.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ type AppsecSource struct {
7676
appsecAllowlistClient *allowlists.AppsecAllowlist
7777
lapiCACertPool *x509.CertPool
7878
authMutex sync.Mutex
79+
httpClient *http.Client
7980
}
8081

8182
// Struct to handle cache of authentication
@@ -306,6 +307,17 @@ func (w *AppsecSource) Configure(yamlConfig []byte, logger *log.Entry, metricsLe
306307
return fmt.Errorf("unable to load LAPI CA cert pool: %w", err)
307308
}
308309

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+
309321
return nil
310322
}
311323

@@ -477,19 +489,7 @@ func (w *AppsecSource) isValidKey(ctx context.Context, apiKey string) (bool, err
477489
req.Header.Add("X-Api-Key", apiKey)
478490
req.Header.Add("User-Agent", useragent.AppsecUserAgent())
479491

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)
493493
if err != nil {
494494
w.logger.Errorf("Error performing request: %s", err)
495495
return false, err

0 commit comments

Comments
 (0)