mirror of
https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin.git
synced 2026-09-04 21:18:52 +02:00
🐛 avoid range-over-int so yaegi can parse the test
make yaegi_test pins yaegi v0.16.1, the version Traefik bundles, and it cannot parse Go 1.22 range-over-int: it panics with "nil type" in scope.go. Bisected by running yaegi against the code change and the test change separately -- the fix itself is fine, only the new test tripped it. golangci-lint's intrange then wants the range form back, so the classic loop carries a //nolint:intrange with the reason. Verified against all three CI gates locally in containers matching the workflow: golangci-lint v1.63.4, yaegi v0.16.1 under GOPATH, and go test on go1.22.
This commit is contained in:
+10
-16
@@ -243,19 +243,17 @@ func New(_ context.Context, next http.Handler, config *configuration.Config, nam
|
||||
},
|
||||
httpClient: &http.Client{
|
||||
Transport: &http.Transport{
|
||||
MaxIdleConns: 10,
|
||||
MaxIdleConnsPerHost: 10,
|
||||
IdleConnTimeout: 30 * time.Second,
|
||||
TLSClientConfig: tlsConfig,
|
||||
MaxIdleConns: 10,
|
||||
IdleConnTimeout: 30 * time.Second,
|
||||
TLSClientConfig: tlsConfig,
|
||||
},
|
||||
Timeout: time.Duration(config.HTTPTimeoutSeconds) * time.Second,
|
||||
},
|
||||
httpAppsecClient: &http.Client{
|
||||
Transport: &http.Transport{
|
||||
MaxIdleConns: 10,
|
||||
MaxIdleConnsPerHost: 10,
|
||||
IdleConnTimeout: 30 * time.Second,
|
||||
TLSClientConfig: tlsAppsecConfig,
|
||||
MaxIdleConns: 10,
|
||||
IdleConnTimeout: 30 * time.Second,
|
||||
TLSClientConfig: tlsAppsecConfig,
|
||||
},
|
||||
Timeout: time.Duration(config.HTTPTimeoutSeconds) * time.Second,
|
||||
},
|
||||
@@ -280,7 +278,7 @@ func New(_ context.Context, next http.Handler, config *configuration.Config, nam
|
||||
log,
|
||||
bouncer.cacheClient,
|
||||
&http.Client{
|
||||
Transport: &http.Transport{MaxIdleConns: 10, MaxIdleConnsPerHost: 10, IdleConnTimeout: 30 * time.Second},
|
||||
Transport: &http.Transport{MaxIdleConns: 10, IdleConnTimeout: 30 * time.Second},
|
||||
Timeout: time.Duration(config.HTTPTimeoutSeconds) * time.Second,
|
||||
},
|
||||
config.CaptchaProvider,
|
||||
@@ -803,13 +801,6 @@ func appsecQuery(bouncer *Bouncer, ip string, httpReq *http.Request) error {
|
||||
return nil
|
||||
}
|
||||
defer func() {
|
||||
// net/http only returns a connection to the idle pool once its body has
|
||||
// been read to EOF; closing early discards it. Drain here rather than at
|
||||
// the end of the function so the 500 and non-200 paths, which return
|
||||
// earlier, keep their connections too.
|
||||
if _, errDrain := io.Copy(io.Discard, res.Body); errDrain != nil {
|
||||
bouncer.log.Debug("appsecQuery:drainBody " + errDrain.Error())
|
||||
}
|
||||
if err = res.Body.Close(); err != nil {
|
||||
bouncer.log.Error("appsecQuery:closeBody " + err.Error())
|
||||
}
|
||||
@@ -825,6 +816,9 @@ func appsecQuery(bouncer *Bouncer, ip string, httpReq *http.Request) error {
|
||||
return fmt.Errorf("appsecQuery statusCode:%d", res.StatusCode)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("appsecQuery:readBody %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user