diff --git a/.golangci.yml b/.golangci.yml index cda97f7fd..e8251d697 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -214,7 +214,6 @@ linters-settings: enable-all: true disabled-checks: - paramTypeCombine - - httpNoBody - ifElseChain - importShadow - hugeParam diff --git a/cmd/crowdsec-cli/clisupport/support.go b/cmd/crowdsec-cli/clisupport/support.go index c87e359db..03545d15b 100644 --- a/cmd/crowdsec-cli/clisupport/support.go +++ b/cmd/crowdsec-cli/clisupport/support.go @@ -113,7 +113,7 @@ func (cli *cliSupport) dumpMetrics(ctx context.Context, db *database.Client, zw return fmt.Errorf("could not format prometheus metrics: %w", err) } - req, err := http.NewRequestWithContext(ctx, http.MethodGet, cfg.Cscli.PrometheusUrl, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, cfg.Cscli.PrometheusUrl, http.NoBody) if err != nil { return fmt.Errorf("could not create request to prometheus endpoint: %w", err) } @@ -328,7 +328,7 @@ func (cli *cliSupport) dumpPprof(ctx context.Context, zw *zip.Writer, prometheus ), endpoint, ), - nil, + http.NoBody, ) if err != nil { return fmt.Errorf("could not create request to pprof endpoint: %w", err) diff --git a/cmd/crowdsec-cli/require/branch.go b/cmd/crowdsec-cli/require/branch.go index ab9b8e50b..b0744a6b4 100644 --- a/cmd/crowdsec-cli/require/branch.go +++ b/cmd/crowdsec-cli/require/branch.go @@ -25,7 +25,7 @@ func lookupLatest(ctx context.Context) (string, error) { url := "https://version.crowdsec.net/latest" - req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody) if err != nil { return "", fmt.Errorf("unable to create request for %s: %w", url, err) } diff --git a/pkg/acquisition/modules/appsec/appsec.go b/pkg/acquisition/modules/appsec/appsec.go index 4b6a52d54..389704b5a 100644 --- a/pkg/acquisition/modules/appsec/appsec.go +++ b/pkg/acquisition/modules/appsec/appsec.go @@ -377,7 +377,7 @@ func (w *AppsecSource) IsAuth(ctx context.Context, apiKey string) bool { Timeout: 200 * time.Millisecond, } - req, err := http.NewRequestWithContext(ctx, http.MethodHead, w.lapiURL, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodHead, w.lapiURL, http.NoBody) if err != nil { log.Errorf("Error creating request: %s", err) return false diff --git a/pkg/acquisition/modules/loki/internal/lokiclient/loki_client.go b/pkg/acquisition/modules/loki/internal/lokiclient/loki_client.go index 5996518e1..f34d96b21 100644 --- a/pkg/acquisition/modules/loki/internal/lokiclient/loki_client.go +++ b/pkg/acquisition/modules/loki/internal/lokiclient/loki_client.go @@ -302,7 +302,7 @@ func (lc *LokiClient) QueryRange(ctx context.Context, infinite bool) chan *LokiQ // Create a wrapper for http.Get to be able to set headers and auth func (lc *LokiClient) Get(ctx context.Context, url string) (*http.Response, error) { - request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) + request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody) if err != nil { return nil, err } diff --git a/pkg/acquisition/modules/victorialogs/internal/vlclient/vl_client.go b/pkg/acquisition/modules/victorialogs/internal/vlclient/vl_client.go index 402754a13..b091b25c1 100644 --- a/pkg/acquisition/modules/victorialogs/internal/vlclient/vl_client.go +++ b/pkg/acquisition/modules/victorialogs/internal/vlclient/vl_client.go @@ -370,7 +370,7 @@ func (lc *VLClient) QueryRange(ctx context.Context, infinite bool) chan *Log { } func (lc *VLClient) Get(ctx context.Context, url string) (*http.Response, error) { - request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) + request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody) if err != nil { return nil, err } diff --git a/pkg/apiclient/decisions_service.go b/pkg/apiclient/decisions_service.go index 0f3f4468c..531b0cdac 100644 --- a/pkg/apiclient/decisions_service.go +++ b/pkg/apiclient/decisions_service.go @@ -183,7 +183,7 @@ func (s *DecisionsService) GetDecisionsFromBlocklist(ctx context.Context, blockl client := http.Client{} - req, err := http.NewRequestWithContext(ctx, http.MethodGet, *blocklist.URL, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, *blocklist.URL, http.NoBody) if err != nil { return nil, false, err } diff --git a/pkg/apiserver/apiserver_test.go b/pkg/apiserver/apiserver_test.go index fb5c0d5e3..fe250aa37 100644 --- a/pkg/apiserver/apiserver_test.go +++ b/pkg/apiserver/apiserver_test.go @@ -337,7 +337,7 @@ func TestUnknownPath(t *testing.T) { router, _ := NewAPITest(t, ctx) w := httptest.NewRecorder() - req, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/test", nil) + req, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/test", http.NoBody) req.Header.Set("User-Agent", UserAgent) router.ServeHTTP(w, req) @@ -396,7 +396,7 @@ func TestLoggingDebugToFileConfig(t *testing.T) { require.NotNil(t, api) w := httptest.NewRecorder() - req, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/test42", nil) + req, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/test42", http.NoBody) req.Header.Set("User-Agent", UserAgent) api.router.ServeHTTP(w, req) assert.Equal(t, http.StatusNotFound, w.Code) @@ -448,7 +448,7 @@ func TestLoggingErrorToFileConfig(t *testing.T) { require.NotNil(t, api) w := httptest.NewRecorder() - req, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/test42", nil) + req, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/test42", http.NoBody) req.Header.Set("User-Agent", UserAgent) api.router.ServeHTTP(w, req) assert.Equal(t, http.StatusNotFound, w.Code) diff --git a/pkg/apiserver/papi.go b/pkg/apiserver/papi.go index cddaabb87..6f50a08fa 100644 --- a/pkg/apiserver/papi.go +++ b/pkg/apiserver/papi.go @@ -160,7 +160,7 @@ func (p *Papi) GetPermissions(ctx context.Context) (PapiPermCheckSuccess, error) httpClient := p.apiClient.GetClient() papiCheckUrl := fmt.Sprintf("%s%s%s", p.URL, types.PAPIVersion, types.PAPIPermissionsUrl) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, papiCheckUrl, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, papiCheckUrl, http.NoBody) if err != nil { return PapiPermCheckSuccess{}, fmt.Errorf("failed to create request: %w", err) } diff --git a/pkg/appsec/ja4h/ja4h_test.go b/pkg/appsec/ja4h/ja4h_test.go index 76d265d8a..434525b0c 100644 --- a/pkg/appsec/ja4h/ja4h_test.go +++ b/pkg/appsec/ja4h/ja4h_test.go @@ -29,7 +29,7 @@ func TestJA4H_A(t *testing.T) { { name: "basic GET request - HTTP1.1 - no accept-language header", request: func() *http.Request { - req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil) + req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody) return req }, expectedResult: "ge11nn000000", @@ -37,7 +37,7 @@ func TestJA4H_A(t *testing.T) { { name: "basic GET request - HTTP1.1 - with accept-language header", request: func() *http.Request { - req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil) + req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody) req.Header.Set("Accept-Language", "en-US") return req }, @@ -46,7 +46,7 @@ func TestJA4H_A(t *testing.T) { { name: "basic POST request - HTTP1.1 - no accept-language header - cookies - referer", request: func() *http.Request { - req, _ := http.NewRequest(http.MethodPost, "http://example.com", nil) + req, _ := http.NewRequest(http.MethodPost, "http://example.com", http.NoBody) req.AddCookie(&http.Cookie{Name: "foo", Value: "bar"}) req.Header.Set("Referer", "http://example.com") return req @@ -56,7 +56,7 @@ func TestJA4H_A(t *testing.T) { { name: "bad accept-language header", request: func() *http.Request { - req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil) + req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody) req.Header.Set("Accept-Language", "aksjdhaslkdhalkjsd") return req }, @@ -65,7 +65,7 @@ func TestJA4H_A(t *testing.T) { { name: "bad accept-language header 2", request: func() *http.Request { - req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil) + req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody) req.Header.Set("Accept-Language", ",") return req }, @@ -94,7 +94,7 @@ func TestJA4H_B(t *testing.T) { { name: "no headers", request: func() *http.Request { - req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil) + req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody) return req }, expectedResult: "e3b0c44298fc", @@ -102,7 +102,7 @@ func TestJA4H_B(t *testing.T) { { name: "header with arbitrary content", request: func() *http.Request { - req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil) + req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody) req.Header.Set("X-Custom-Header", "some value") return req }, @@ -111,7 +111,7 @@ func TestJA4H_B(t *testing.T) { { name: "header with multiple headers", request: func() *http.Request { - req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil) + req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody) req.Header.Set("X-Custom-Header", "some value") req.Header.Set("Authorization", "Bearer token") return req @@ -121,7 +121,7 @@ func TestJA4H_B(t *testing.T) { { name: "curl-like request", request: func() *http.Request { - req, _ := http.NewRequest(http.MethodGet, "http://localhost", nil) + req, _ := http.NewRequest(http.MethodGet, "http://localhost", http.NoBody) req.Header.Set("Host", "localhost") req.Header.Set("User-Agent", "curl/8.12.1") req.Header.Set("Accept", "*/*") @@ -150,7 +150,7 @@ func TestJA4H_C(t *testing.T) { { name: "no cookies", cookies: func() []*http.Cookie { - req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil) + req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody) return req.Cookies() }, expectedResult: "000000000000", @@ -158,7 +158,7 @@ func TestJA4H_C(t *testing.T) { { name: "one cookie", cookies: func() []*http.Cookie { - req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil) + req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody) req.AddCookie(&http.Cookie{Name: "foo", Value: "bar"}) return req.Cookies() }, @@ -167,7 +167,7 @@ func TestJA4H_C(t *testing.T) { { name: "duplicate cookies", cookies: func() []*http.Cookie { - req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil) + req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody) req.AddCookie(&http.Cookie{Name: "foo", Value: "bar"}) req.AddCookie(&http.Cookie{Name: "foo", Value: "bar2"}) return req.Cookies() @@ -177,7 +177,7 @@ func TestJA4H_C(t *testing.T) { { name: "multiple cookies", cookies: func() []*http.Cookie { - req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil) + req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody) req.AddCookie(&http.Cookie{Name: "foo", Value: "bar"}) req.AddCookie(&http.Cookie{Name: "bar", Value: "foo"}) cookies := req.Cookies() @@ -209,7 +209,7 @@ func TestJA4H_D(t *testing.T) { { name: "no cookies", cookies: func() []*http.Cookie { - req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil) + req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody) return req.Cookies() }, expectedResult: "000000000000", @@ -217,7 +217,7 @@ func TestJA4H_D(t *testing.T) { { name: "one cookie", cookies: func() []*http.Cookie { - req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil) + req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody) req.AddCookie(&http.Cookie{Name: "foo", Value: "bar"}) return req.Cookies() }, @@ -226,7 +226,7 @@ func TestJA4H_D(t *testing.T) { { name: "duplicate cookies", cookies: func() []*http.Cookie { - req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil) + req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody) req.AddCookie(&http.Cookie{Name: "foo", Value: "bar"}) req.AddCookie(&http.Cookie{Name: "foo", Value: "bar2"}) return req.Cookies() @@ -236,7 +236,7 @@ func TestJA4H_D(t *testing.T) { { name: "multiple cookies", cookies: func() []*http.Cookie { - req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil) + req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody) req.AddCookie(&http.Cookie{Name: "foo", Value: "bar"}) req.AddCookie(&http.Cookie{Name: "bar", Value: "foo"}) cookies := req.Cookies() @@ -268,7 +268,7 @@ func TestJA4H(t *testing.T) { { name: "Basic GET - No cookies", req: func() *http.Request { - req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil) + req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody) return req }, expectedHash: "ge11nn000000_e3b0c44298fc_000000000000_000000000000", @@ -276,7 +276,7 @@ func TestJA4H(t *testing.T) { { name: "Basic GET - With cookies", req: func() *http.Request { - req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil) + req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody) req.AddCookie(&http.Cookie{Name: "session", Value: "12345"}) return req }, @@ -285,7 +285,7 @@ func TestJA4H(t *testing.T) { { name: "Basic GET - Multiple cookies", req: func() *http.Request { - req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil) + req, _ := http.NewRequest(http.MethodGet, "http://example.com", http.NoBody) req.AddCookie(&http.Cookie{Name: "foo", Value: "bar"}) req.AddCookie(&http.Cookie{Name: "baz", Value: "qux"}) return req diff --git a/pkg/cticlient/client.go b/pkg/cticlient/client.go index b15766dd9..56f35b8a5 100644 --- a/pkg/cticlient/client.go +++ b/pkg/cticlient/client.go @@ -42,8 +42,7 @@ func (c *CrowdsecCTIClient) doRequest(ctx context.Context, method string, endpoi url += fmt.Sprintf("%s=%s&", k, v) } } - - req, err := http.NewRequestWithContext(ctx, method, url, nil) + req, err := http.NewRequestWithContext(ctx, method, url, http.NoBody) if err != nil { return nil, err } diff --git a/pkg/exprhelpers/waf_test.go b/pkg/exprhelpers/waf_test.go index bfab22bb2..39696cea6 100644 --- a/pkg/exprhelpers/waf_test.go +++ b/pkg/exprhelpers/waf_test.go @@ -314,7 +314,7 @@ func TestJA4H(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - req, err := http.NewRequest(test.method, test.url, nil) + req, err := http.NewRequest(test.method, test.url, http.NoBody) if err != nil { t.Fatalf("Failed to create request: %s", err) } diff --git a/pkg/longpollclient/client.go b/pkg/longpollclient/client.go index 6a668e07d..eddcc904f 100644 --- a/pkg/longpollclient/client.go +++ b/pkg/longpollclient/client.go @@ -60,7 +60,7 @@ func (c *LongPollClient) doQuery(ctx context.Context) (*http.Response, error) { logger.Debugf("Query parameters: %s", c.url.RawQuery) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.url.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.url.String(), http.NoBody) if err != nil { logger.Errorf("failed to create request: %s", err) return nil, err