From 469afa5f8fbcadc46b05571fe65ba028c55d8876 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Mon, 26 May 2025 22:30:15 +0200 Subject: [PATCH] fix httpNoBody from go-critic Signed-off-by: Matthieu MOREL --- .golangci.yml | 1 - api/server/httputils/form_test.go | 14 ++++++------- api/server/httputils/httputils_test.go | 2 +- api/server/middleware/version_test.go | 4 ++-- .../router/volume/volume_routes_test.go | 20 +++++++++---------- api/server/server_test.go | 2 +- client/client_test.go | 2 +- client/hijack.go | 2 +- daemon/logger/splunk/splunk.go | 2 +- daemon/logger/splunk/splunk_test.go | 2 +- integration/plugin/authz/authz_plugin_test.go | 4 ++-- pkg/authorization/api_test.go | 2 +- pkg/authorization/middleware_unix_test.go | 2 +- registry/auth.go | 4 ++-- .../resumable/resumablerequestreader_test.go | 18 ++++++++--------- registry/search_endpoint_v1.go | 2 +- registry/search_endpoint_v1_test.go | 12 +++++------ registry/search_session.go | 2 +- testutil/daemon/daemon.go | 4 ++-- testutil/request/request.go | 2 +- 20 files changed, 51 insertions(+), 52 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index f2cd60bfe2..399c146f70 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -127,7 +127,6 @@ linters: - exposedSyncMutex - filepathJoin - hexLiteral - - httpNoBody - hugeParam - ifElseChain - importShadow diff --git a/api/server/httputils/form_test.go b/api/server/httputils/form_test.go index 66b10cb6be..b46a58e6d0 100644 --- a/api/server/httputils/form_test.go +++ b/api/server/httputils/form_test.go @@ -30,7 +30,7 @@ func TestBoolValue(t *testing.T) { for c, e := range cases { v := url.Values{} v.Set("test", c) - r, _ := http.NewRequest(http.MethodPost, "", nil) + r, _ := http.NewRequest(http.MethodPost, "", http.NoBody) r.Form = v a := BoolValue(r, "test") @@ -41,14 +41,14 @@ func TestBoolValue(t *testing.T) { } func TestBoolValueOrDefault(t *testing.T) { - r, _ := http.NewRequest(http.MethodGet, "", nil) + r, _ := http.NewRequest(http.MethodGet, "", http.NoBody) if !BoolValueOrDefault(r, "queryparam", true) { t.Fatal("Expected to get true default value, got false") } v := url.Values{} v.Set("param", "") - r, _ = http.NewRequest(http.MethodGet, "", nil) + r, _ = http.NewRequest(http.MethodGet, "", http.NoBody) r.Form = v if BoolValueOrDefault(r, "param", true) { t.Fatal("Expected not to get true") @@ -66,7 +66,7 @@ func TestInt64ValueOrZero(t *testing.T) { for c, e := range cases { v := url.Values{} v.Set("test", c) - r, _ := http.NewRequest(http.MethodPost, "", nil) + r, _ := http.NewRequest(http.MethodPost, "", http.NoBody) r.Form = v a := Int64ValueOrZero(r, "test") @@ -86,7 +86,7 @@ func TestInt64ValueOrDefault(t *testing.T) { for c, e := range cases { v := url.Values{} v.Set("test", c) - r, _ := http.NewRequest(http.MethodPost, "", nil) + r, _ := http.NewRequest(http.MethodPost, "", http.NoBody) r.Form = v a, err := Int64ValueOrDefault(r, "test", -1) @@ -102,7 +102,7 @@ func TestInt64ValueOrDefault(t *testing.T) { func TestInt64ValueOrDefaultWithError(t *testing.T) { v := url.Values{} v.Set("test", "invalid") - r, _ := http.NewRequest(http.MethodPost, "", nil) + r, _ := http.NewRequest(http.MethodPost, "", http.NoBody) r.Form = v _, err := Int64ValueOrDefault(r, "test", -1) @@ -150,7 +150,7 @@ func TestUint32Value(t *testing.T) { } for _, tc := range tests { t.Run(tc.value, func(t *testing.T) { - r, _ := http.NewRequest(http.MethodPost, "", nil) + r, _ := http.NewRequest(http.MethodPost, "", http.NoBody) r.Form = url.Values{} if tc.value != valueNotSet { r.Form.Set("field", tc.value) diff --git a/api/server/httputils/httputils_test.go b/api/server/httputils/httputils_test.go index f9ff55a00a..76f2c2a4c1 100644 --- a/api/server/httputils/httputils_test.go +++ b/api/server/httputils/httputils_test.go @@ -33,7 +33,7 @@ func TestJsonContentType(t *testing.T) { func TestReadJSON(t *testing.T) { t.Run("nil body", func(t *testing.T) { - req, err := http.NewRequest(http.MethodPost, "https://example.com/some/path", nil) + req, err := http.NewRequest(http.MethodPost, "https://example.com/some/path", http.NoBody) if err != nil { t.Error(err) } diff --git a/api/server/middleware/version_test.go b/api/server/middleware/version_test.go index a67a609d21..cc7928f471 100644 --- a/api/server/middleware/version_test.go +++ b/api/server/middleware/version_test.go @@ -79,7 +79,7 @@ func TestVersionMiddlewareVersion(t *testing.T) { assert.NilError(t, err) h := m.WrapHandler(handler) - req, _ := http.NewRequest(http.MethodGet, "/containers/json", nil) + req, _ := http.NewRequest(http.MethodGet, "/containers/json", http.NoBody) resp := httptest.NewRecorder() ctx := context.Background() @@ -129,7 +129,7 @@ func TestVersionMiddlewareWithErrorsReturnsHeaders(t *testing.T) { assert.NilError(t, err) h := m.WrapHandler(handler) - req, _ := http.NewRequest(http.MethodGet, "/containers/json", nil) + req, _ := http.NewRequest(http.MethodGet, "/containers/json", http.NoBody) resp := httptest.NewRecorder() ctx := context.Background() diff --git a/api/server/router/volume/volume_routes_test.go b/api/server/router/volume/volume_routes_test.go index 2315636ddc..0dbee353e6 100644 --- a/api/server/router/volume/volume_routes_test.go +++ b/api/server/router/volume/volume_routes_test.go @@ -22,7 +22,7 @@ import ( func callGetVolume(v *volumeRouter, name string) (*httptest.ResponseRecorder, error) { ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) vars := map[string]string{"name": name} - req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/volumes/%s", name), nil) + req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/volumes/%s", name), http.NoBody) resp := httptest.NewRecorder() err := v.getVolumeByName(ctx, resp, req, vars) @@ -32,7 +32,7 @@ func callGetVolume(v *volumeRouter, name string) (*httptest.ResponseRecorder, er func callListVolumes(v *volumeRouter) (*httptest.ResponseRecorder, error) { ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) vars := map[string]string{} - req := httptest.NewRequest(http.MethodGet, "/volumes", nil) + req := httptest.NewRequest(http.MethodGet, "/volumes", http.NoBody) resp := httptest.NewRecorder() err := v.getVolumesList(ctx, resp, req, vars) @@ -428,7 +428,7 @@ func TestVolumeRemove(t *testing.T) { } ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", nil) + req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", http.NoBody) resp := httptest.NewRecorder() err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"}) @@ -455,7 +455,7 @@ func TestVolumeRemoveSwarm(t *testing.T) { } ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", nil) + req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", http.NoBody) resp := httptest.NewRecorder() err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"}) @@ -472,7 +472,7 @@ func TestVolumeRemoveNotFoundNoSwarm(t *testing.T) { } ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", nil) + req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", http.NoBody) resp := httptest.NewRecorder() err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"}) @@ -489,7 +489,7 @@ func TestVolumeRemoveNotFoundNoManager(t *testing.T) { } ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", nil) + req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", http.NoBody) resp := httptest.NewRecorder() err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"}) @@ -513,7 +513,7 @@ func TestVolumeRemoveFoundNoSwarm(t *testing.T) { } ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", nil) + req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", http.NoBody) resp := httptest.NewRecorder() err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"}) @@ -536,7 +536,7 @@ func TestVolumeRemoveNoSwarmInUse(t *testing.T) { } ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest(http.MethodDelete, "/volumes/inuse", nil) + req := httptest.NewRequest(http.MethodDelete, "/volumes/inuse", http.NoBody) resp := httptest.NewRecorder() err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "inuse"}) @@ -564,7 +564,7 @@ func TestVolumeRemoveSwarmForce(t *testing.T) { } ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", nil) + req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", http.NoBody) resp := httptest.NewRecorder() err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"}) @@ -573,7 +573,7 @@ func TestVolumeRemoveSwarmForce(t *testing.T) { assert.Assert(t, cerrdefs.IsConflict(err)) ctx = context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion) - req = httptest.NewRequest(http.MethodDelete, "/volumes/vol1?force=1", nil) + req = httptest.NewRequest(http.MethodDelete, "/volumes/vol1?force=1", http.NoBody) resp = httptest.NewRecorder() err = v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"}) diff --git a/api/server/server_test.go b/api/server/server_test.go index 6e8453c725..860e11c5f6 100644 --- a/api/server/server_test.go +++ b/api/server/server_test.go @@ -21,7 +21,7 @@ func TestMiddlewares(t *testing.T) { } srv.UseMiddleware(*m) - req, _ := http.NewRequest(http.MethodGet, "/containers/json", nil) + req, _ := http.NewRequest(http.MethodGet, "/containers/json", http.NoBody) resp := httptest.NewRecorder() ctx := context.Background() diff --git a/client/client_test.go b/client/client_test.go index a0d25c357c..2e442f72cb 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -525,7 +525,7 @@ func TestClientRedirect(t *testing.T) { for _, tc := range tests { t.Run(tc.httpMethod, func(t *testing.T) { - req, err := http.NewRequest(tc.httpMethod, "/redirectme", nil) + req, err := http.NewRequest(tc.httpMethod, "/redirectme", http.NoBody) assert.NilError(t, err) resp, err := client.Do(req) assert.Check(t, is.Equal(resp.StatusCode, tc.statusCode)) diff --git a/client/hijack.go b/client/hijack.go index 07b2e7f695..01d121a62e 100644 --- a/client/hijack.go +++ b/client/hijack.go @@ -40,7 +40,7 @@ func (cli *Client) postHijacked(ctx context.Context, path string, query url.Valu // DialHijack returns a hijacked connection with negotiated protocol proto. func (cli *Client) DialHijack(ctx context.Context, url, proto string, meta map[string][]string) (net.Conn, error) { - req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, http.NoBody) if err != nil { return nil, err } diff --git a/daemon/logger/splunk/splunk.go b/daemon/logger/splunk/splunk.go index 8111ff2d44..c71bed658c 100644 --- a/daemon/logger/splunk/splunk.go +++ b/daemon/logger/splunk/splunk.go @@ -603,7 +603,7 @@ func parseURL(info logger.Info) (*url.URL, error) { } func verifySplunkConnection(l *splunkLogger) error { - req, err := http.NewRequest(http.MethodOptions, l.url, nil) + req, err := http.NewRequest(http.MethodOptions, l.url, http.NoBody) if err != nil { return err } diff --git a/daemon/logger/splunk/splunk_test.go b/daemon/logger/splunk/splunk_test.go index 854ce7e402..7f339bd3d3 100644 --- a/daemon/logger/splunk/splunk_test.go +++ b/daemon/logger/splunk/splunk_test.go @@ -103,7 +103,7 @@ func TestNewWithProxy(t *testing.T) { proxyFunc := splunkLogger.transport.Proxy assert.Assert(t, proxyFunc != nil) - req, err := http.NewRequest(http.MethodGet, splunkURL, nil) + req, err := http.NewRequest(http.MethodGet, splunkURL, http.NoBody) assert.NilError(t, err) proxyURL, err := proxyFunc(req) diff --git a/integration/plugin/authz/authz_plugin_test.go b/integration/plugin/authz/authz_plugin_test.go index 29c9e4f77f..e1fde67df2 100644 --- a/integration/plugin/authz/authz_plugin_test.go +++ b/integration/plugin/authz/authz_plugin_test.go @@ -190,7 +190,7 @@ func TestAuthZPluginAPIDenyResponse(t *testing.T) { socketClient, err := socketHTTPClient(daemonURL) assert.NilError(t, err) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, "/version", nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, "/version", http.NoBody) assert.NilError(t, err) req.URL.Scheme = "http" req.URL.Host = client.DummyHost @@ -486,7 +486,7 @@ func TestAuthZPluginHeader(t *testing.T) { socketClient, err := socketHTTPClient(daemonURL) assert.NilError(t, err) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, "/version", nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, "/version", http.NoBody) assert.NilError(t, err) req.URL.Scheme = "http" req.URL.Host = client.DummyHost diff --git a/pkg/authorization/api_test.go b/pkg/authorization/api_test.go index fe71e597c6..6205142e65 100644 --- a/pkg/authorization/api_test.go +++ b/pkg/authorization/api_test.go @@ -46,7 +46,7 @@ func TestPeerCertificateMarshalJSON(t *testing.T) { certs := []*x509.Certificate{cert} addr := "www.authz.com/auth" - req, err := http.NewRequest(http.MethodGet, addr, nil) + req, err := http.NewRequest(http.MethodGet, addr, http.NoBody) assert.NilError(t, err) req.RequestURI = addr diff --git a/pkg/authorization/middleware_unix_test.go b/pkg/authorization/middleware_unix_test.go index 9abe5d4dcb..1ecad0217d 100644 --- a/pkg/authorization/middleware_unix_test.go +++ b/pkg/authorization/middleware_unix_test.go @@ -33,7 +33,7 @@ func TestMiddlewareWrapHandler(t *testing.T) { assert.Assert(t, mdHandler != nil) addr := "www.example.com/auth" - req, _ := http.NewRequest(http.MethodGet, addr, nil) + req, _ := http.NewRequest(http.MethodGet, addr, http.NoBody) req.RequestURI = addr req.Header.Add("header", "value") diff --git a/registry/auth.go b/registry/auth.go index be26c65beb..1b0eeeed0b 100644 --- a/registry/auth.go +++ b/registry/auth.go @@ -70,7 +70,7 @@ func loginV2(ctx context.Context, authConfig *registry.AuthConfig, endpoint APIE endpointStr := strings.TrimRight(endpoint.URL.String(), "/") + "/v2/" log.G(ctx).WithField("endpoint", endpointStr).Debug("attempting v2 login to registry endpoint") - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpointStr, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpointStr, http.NoBody) if err != nil { return "", err } @@ -181,7 +181,7 @@ func PingV2Registry(endpoint *url.URL, transport http.RoundTripper) (challenge.M Timeout: 15 * time.Second, } endpointStr := strings.TrimRight(endpoint.String(), "/") + "/v2/" - req, err := http.NewRequest(http.MethodGet, endpointStr, nil) + req, err := http.NewRequest(http.MethodGet, endpointStr, http.NoBody) if err != nil { return nil, err } diff --git a/registry/resumable/resumablerequestreader_test.go b/registry/resumable/resumablerequestreader_test.go index 30ae6cd611..718279f273 100644 --- a/registry/resumable/resumablerequestreader_test.go +++ b/registry/resumable/resumablerequestreader_test.go @@ -22,7 +22,7 @@ func TestResumableRequestHeaderSimpleErrors(t *testing.T) { client := &http.Client{} var req *http.Request - req, err := http.NewRequest(http.MethodGet, ts.URL, nil) + req, err := http.NewRequest(http.MethodGet, ts.URL, http.NoBody) assert.NilError(t, err) resreq := &requestReader{} @@ -43,7 +43,7 @@ func TestResumableRequestHeaderNotTooMuchFailures(t *testing.T) { client := &http.Client{} var badReq *http.Request - badReq, err := http.NewRequest(http.MethodGet, "I'm not an url", nil) + badReq, err := http.NewRequest(http.MethodGet, "I'm not an url", http.NoBody) assert.NilError(t, err) resreq := &requestReader{ @@ -63,7 +63,7 @@ func TestResumableRequestHeaderTooMuchFailures(t *testing.T) { client := &http.Client{} var badReq *http.Request - badReq, err := http.NewRequest(http.MethodGet, "I'm not an url", nil) + badReq, err := http.NewRequest(http.MethodGet, "I'm not an url", http.NoBody) assert.NilError(t, err) resreq := &requestReader{ @@ -92,7 +92,7 @@ func (errorReaderCloser) Read(p []byte) (int, error) { // If an unknown error is encountered, return 0, nil and log it func TestResumableRequestReaderWithReadError(t *testing.T) { var req *http.Request - req, err := http.NewRequest(http.MethodGet, "", nil) + req, err := http.NewRequest(http.MethodGet, "", http.NoBody) assert.NilError(t, err) client := &http.Client{} @@ -123,7 +123,7 @@ func TestResumableRequestReaderWithReadError(t *testing.T) { func TestResumableRequestReaderWithEOFWith416Response(t *testing.T) { var req *http.Request - req, err := http.NewRequest(http.MethodGet, "", nil) + req, err := http.NewRequest(http.MethodGet, "", http.NoBody) assert.NilError(t, err) client := &http.Client{} @@ -159,7 +159,7 @@ func TestResumableRequestReaderWithServerDoesntSupportByteRanges(t *testing.T) { defer ts.Close() var req *http.Request - req, err := http.NewRequest(http.MethodGet, ts.URL, nil) + req, err := http.NewRequest(http.MethodGet, ts.URL, http.NoBody) assert.NilError(t, err) client := &http.Client{} @@ -185,7 +185,7 @@ func TestResumableRequestReaderWithZeroTotalSize(t *testing.T) { defer ts.Close() var req *http.Request - req, err := http.NewRequest(http.MethodGet, ts.URL, nil) + req, err := http.NewRequest(http.MethodGet, ts.URL, http.NoBody) assert.NilError(t, err) client := &http.Client{} @@ -210,7 +210,7 @@ func TestResumableRequestReader(t *testing.T) { defer ts.Close() var req *http.Request - req, err := http.NewRequest(http.MethodGet, ts.URL, nil) + req, err := http.NewRequest(http.MethodGet, ts.URL, http.NoBody) assert.NilError(t, err) client := &http.Client{} @@ -236,7 +236,7 @@ func TestResumableRequestReaderWithInitialResponse(t *testing.T) { defer ts.Close() var req *http.Request - req, err := http.NewRequest(http.MethodGet, ts.URL, nil) + req, err := http.NewRequest(http.MethodGet, ts.URL, http.NoBody) assert.NilError(t, err) client := &http.Client{} diff --git a/registry/search_endpoint_v1.go b/registry/search_endpoint_v1.go index ed30233a13..2ac3cee829 100644 --- a/registry/search_endpoint_v1.go +++ b/registry/search_endpoint_v1.go @@ -122,7 +122,7 @@ func (e *v1Endpoint) ping(ctx context.Context) (v1PingResult, error) { pingURL := e.String() + "_ping" log.G(ctx).WithField("url", pingURL).Debug("attempting v1 ping for registry endpoint") - req, err := http.NewRequestWithContext(ctx, http.MethodGet, pingURL, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, pingURL, http.NoBody) if err != nil { return v1PingResult{}, invalidParam(err) } diff --git a/registry/search_endpoint_v1_test.go b/registry/search_endpoint_v1_test.go index bd6d0b32bd..a430f34cc1 100644 --- a/registry/search_endpoint_v1_test.go +++ b/registry/search_endpoint_v1_test.go @@ -175,12 +175,12 @@ func TestV1EndpointValidate(t *testing.T) { func TestTrustedLocation(t *testing.T) { for _, u := range []string{"http://example.com", "https://example.com:7777", "http://docker.io", "http://test.docker.com", "https://fakedocker.com"} { - req, _ := http.NewRequest(http.MethodGet, u, nil) + req, _ := http.NewRequest(http.MethodGet, u, http.NoBody) assert.Check(t, !trustedLocation(req)) } for _, u := range []string{"https://docker.io", "https://test.docker.com:80"} { - req, _ := http.NewRequest(http.MethodGet, u, nil) + req, _ := http.NewRequest(http.MethodGet, u, http.NoBody) assert.Check(t, trustedLocation(req)) } } @@ -191,10 +191,10 @@ func TestAddRequiredHeadersToRedirectedRequests(t *testing.T) { {"https://foo.docker.io:7777", "http://bar.docker.com"}, {"https://foo.docker.io", "https://example.com"}, } { - reqFrom, _ := http.NewRequest(http.MethodGet, urls[0], nil) + reqFrom, _ := http.NewRequest(http.MethodGet, urls[0], http.NoBody) reqFrom.Header.Add("Content-Type", "application/json") reqFrom.Header.Add("Authorization", "super_secret") - reqTo, _ := http.NewRequest(http.MethodGet, urls[1], nil) + reqTo, _ := http.NewRequest(http.MethodGet, urls[1], http.NoBody) _ = addRequiredHeadersToRedirectedRequests(reqTo, []*http.Request{reqFrom}) @@ -215,10 +215,10 @@ func TestAddRequiredHeadersToRedirectedRequests(t *testing.T) { {"https://docker.io", "https://docker.com"}, {"https://foo.docker.io:7777", "https://bar.docker.com"}, } { - reqFrom, _ := http.NewRequest(http.MethodGet, urls[0], nil) + reqFrom, _ := http.NewRequest(http.MethodGet, urls[0], http.NoBody) reqFrom.Header.Add("Content-Type", "application/json") reqFrom.Header.Add("Authorization", "super_secret") - reqTo, _ := http.NewRequest(http.MethodGet, urls[1], nil) + reqTo, _ := http.NewRequest(http.MethodGet, urls[1], http.NoBody) _ = addRequiredHeadersToRedirectedRequests(reqTo, []*http.Request{reqFrom}) diff --git a/registry/search_session.go b/registry/search_session.go index bcb7f8cd0d..65b287a070 100644 --- a/registry/search_session.go +++ b/registry/search_session.go @@ -222,7 +222,7 @@ func (r *session) searchRepositories(ctx context.Context, term string, limit int u := r.indexEndpoint.String() + "search?q=" + url.QueryEscape(term) + "&n=" + url.QueryEscape(fmt.Sprintf("%d", limit)) log.G(ctx).WithField("url", u).Debug("searchRepositories") - req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, http.NoBody) if err != nil { return nil, invalidParamWrapf(err, "error building request") } diff --git a/testutil/daemon/daemon.go b/testutil/daemon/daemon.go index d7ca68db37..8e7b0f3b44 100644 --- a/testutil/daemon/daemon.go +++ b/testutil/daemon/daemon.go @@ -572,7 +572,7 @@ func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error { Transport: clientConfig.transport, } - req, err := http.NewRequest(http.MethodGet, "/_ping", nil) + req, err := http.NewRequest(http.MethodGet, "/_ping", http.NoBody) if err != nil { return errors.Wrapf(err, "[%s] could not create new request", d.id) } @@ -947,7 +947,7 @@ func (d *Daemon) queryRootDir() (string, error) { Transport: clientConfig.transport, } - req, err := http.NewRequest(http.MethodGet, "/info", nil) + req, err := http.NewRequest(http.MethodGet, "/info", http.NoBody) if err != nil { return "", err } diff --git a/testutil/request/request.go b/testutil/request/request.go index 5ef87098d1..9cfb0aa4de 100644 --- a/testutil/request/request.go +++ b/testutil/request/request.go @@ -117,7 +117,7 @@ func newRequest(endpoint string, opts *Options) (*http.Request, error) { if err != nil { return nil, errors.Wrapf(err, "failed parsing url %q", opts.host) } - req, err := http.NewRequest(http.MethodGet, endpoint, nil) + req, err := http.NewRequest(http.MethodGet, endpoint, http.NoBody) if err != nil { return nil, errors.Wrap(err, "failed to create request") }