Browse code

fix httpNoBody from go-critic

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>

Matthieu MOREL authored on 2025/05/27 05:30:15
Showing 20 changed files
... ...
@@ -127,7 +127,6 @@ linters:
127 127
         - exposedSyncMutex
128 128
         - filepathJoin
129 129
         - hexLiteral
130
-        - httpNoBody
131 130
         - hugeParam
132 131
         - ifElseChain
133 132
         - importShadow
... ...
@@ -30,7 +30,7 @@ func TestBoolValue(t *testing.T) {
30 30
 	for c, e := range cases {
31 31
 		v := url.Values{}
32 32
 		v.Set("test", c)
33
-		r, _ := http.NewRequest(http.MethodPost, "", nil)
33
+		r, _ := http.NewRequest(http.MethodPost, "", http.NoBody)
34 34
 		r.Form = v
35 35
 
36 36
 		a := BoolValue(r, "test")
... ...
@@ -41,14 +41,14 @@ func TestBoolValue(t *testing.T) {
41 41
 }
42 42
 
43 43
 func TestBoolValueOrDefault(t *testing.T) {
44
-	r, _ := http.NewRequest(http.MethodGet, "", nil)
44
+	r, _ := http.NewRequest(http.MethodGet, "", http.NoBody)
45 45
 	if !BoolValueOrDefault(r, "queryparam", true) {
46 46
 		t.Fatal("Expected to get true default value, got false")
47 47
 	}
48 48
 
49 49
 	v := url.Values{}
50 50
 	v.Set("param", "")
51
-	r, _ = http.NewRequest(http.MethodGet, "", nil)
51
+	r, _ = http.NewRequest(http.MethodGet, "", http.NoBody)
52 52
 	r.Form = v
53 53
 	if BoolValueOrDefault(r, "param", true) {
54 54
 		t.Fatal("Expected not to get true")
... ...
@@ -66,7 +66,7 @@ func TestInt64ValueOrZero(t *testing.T) {
66 66
 	for c, e := range cases {
67 67
 		v := url.Values{}
68 68
 		v.Set("test", c)
69
-		r, _ := http.NewRequest(http.MethodPost, "", nil)
69
+		r, _ := http.NewRequest(http.MethodPost, "", http.NoBody)
70 70
 		r.Form = v
71 71
 
72 72
 		a := Int64ValueOrZero(r, "test")
... ...
@@ -86,7 +86,7 @@ func TestInt64ValueOrDefault(t *testing.T) {
86 86
 	for c, e := range cases {
87 87
 		v := url.Values{}
88 88
 		v.Set("test", c)
89
-		r, _ := http.NewRequest(http.MethodPost, "", nil)
89
+		r, _ := http.NewRequest(http.MethodPost, "", http.NoBody)
90 90
 		r.Form = v
91 91
 
92 92
 		a, err := Int64ValueOrDefault(r, "test", -1)
... ...
@@ -102,7 +102,7 @@ func TestInt64ValueOrDefault(t *testing.T) {
102 102
 func TestInt64ValueOrDefaultWithError(t *testing.T) {
103 103
 	v := url.Values{}
104 104
 	v.Set("test", "invalid")
105
-	r, _ := http.NewRequest(http.MethodPost, "", nil)
105
+	r, _ := http.NewRequest(http.MethodPost, "", http.NoBody)
106 106
 	r.Form = v
107 107
 
108 108
 	_, err := Int64ValueOrDefault(r, "test", -1)
... ...
@@ -150,7 +150,7 @@ func TestUint32Value(t *testing.T) {
150 150
 	}
151 151
 	for _, tc := range tests {
152 152
 		t.Run(tc.value, func(t *testing.T) {
153
-			r, _ := http.NewRequest(http.MethodPost, "", nil)
153
+			r, _ := http.NewRequest(http.MethodPost, "", http.NoBody)
154 154
 			r.Form = url.Values{}
155 155
 			if tc.value != valueNotSet {
156 156
 				r.Form.Set("field", tc.value)
... ...
@@ -33,7 +33,7 @@ func TestJsonContentType(t *testing.T) {
33 33
 
34 34
 func TestReadJSON(t *testing.T) {
35 35
 	t.Run("nil body", func(t *testing.T) {
36
-		req, err := http.NewRequest(http.MethodPost, "https://example.com/some/path", nil)
36
+		req, err := http.NewRequest(http.MethodPost, "https://example.com/some/path", http.NoBody)
37 37
 		if err != nil {
38 38
 			t.Error(err)
39 39
 		}
... ...
@@ -79,7 +79,7 @@ func TestVersionMiddlewareVersion(t *testing.T) {
79 79
 	assert.NilError(t, err)
80 80
 	h := m.WrapHandler(handler)
81 81
 
82
-	req, _ := http.NewRequest(http.MethodGet, "/containers/json", nil)
82
+	req, _ := http.NewRequest(http.MethodGet, "/containers/json", http.NoBody)
83 83
 	resp := httptest.NewRecorder()
84 84
 	ctx := context.Background()
85 85
 
... ...
@@ -129,7 +129,7 @@ func TestVersionMiddlewareWithErrorsReturnsHeaders(t *testing.T) {
129 129
 	assert.NilError(t, err)
130 130
 	h := m.WrapHandler(handler)
131 131
 
132
-	req, _ := http.NewRequest(http.MethodGet, "/containers/json", nil)
132
+	req, _ := http.NewRequest(http.MethodGet, "/containers/json", http.NoBody)
133 133
 	resp := httptest.NewRecorder()
134 134
 	ctx := context.Background()
135 135
 
... ...
@@ -22,7 +22,7 @@ import (
22 22
 func callGetVolume(v *volumeRouter, name string) (*httptest.ResponseRecorder, error) {
23 23
 	ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion)
24 24
 	vars := map[string]string{"name": name}
25
-	req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/volumes/%s", name), nil)
25
+	req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/volumes/%s", name), http.NoBody)
26 26
 	resp := httptest.NewRecorder()
27 27
 
28 28
 	err := v.getVolumeByName(ctx, resp, req, vars)
... ...
@@ -32,7 +32,7 @@ func callGetVolume(v *volumeRouter, name string) (*httptest.ResponseRecorder, er
32 32
 func callListVolumes(v *volumeRouter) (*httptest.ResponseRecorder, error) {
33 33
 	ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion)
34 34
 	vars := map[string]string{}
35
-	req := httptest.NewRequest(http.MethodGet, "/volumes", nil)
35
+	req := httptest.NewRequest(http.MethodGet, "/volumes", http.NoBody)
36 36
 	resp := httptest.NewRecorder()
37 37
 
38 38
 	err := v.getVolumesList(ctx, resp, req, vars)
... ...
@@ -428,7 +428,7 @@ func TestVolumeRemove(t *testing.T) {
428 428
 	}
429 429
 
430 430
 	ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion)
431
-	req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", nil)
431
+	req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", http.NoBody)
432 432
 	resp := httptest.NewRecorder()
433 433
 
434 434
 	err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"})
... ...
@@ -455,7 +455,7 @@ func TestVolumeRemoveSwarm(t *testing.T) {
455 455
 	}
456 456
 
457 457
 	ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion)
458
-	req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", nil)
458
+	req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", http.NoBody)
459 459
 	resp := httptest.NewRecorder()
460 460
 
461 461
 	err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"})
... ...
@@ -472,7 +472,7 @@ func TestVolumeRemoveNotFoundNoSwarm(t *testing.T) {
472 472
 	}
473 473
 
474 474
 	ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion)
475
-	req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", nil)
475
+	req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", http.NoBody)
476 476
 	resp := httptest.NewRecorder()
477 477
 
478 478
 	err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"})
... ...
@@ -489,7 +489,7 @@ func TestVolumeRemoveNotFoundNoManager(t *testing.T) {
489 489
 	}
490 490
 
491 491
 	ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion)
492
-	req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", nil)
492
+	req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", http.NoBody)
493 493
 	resp := httptest.NewRecorder()
494 494
 
495 495
 	err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"})
... ...
@@ -513,7 +513,7 @@ func TestVolumeRemoveFoundNoSwarm(t *testing.T) {
513 513
 	}
514 514
 
515 515
 	ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion)
516
-	req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", nil)
516
+	req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", http.NoBody)
517 517
 	resp := httptest.NewRecorder()
518 518
 
519 519
 	err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"})
... ...
@@ -536,7 +536,7 @@ func TestVolumeRemoveNoSwarmInUse(t *testing.T) {
536 536
 	}
537 537
 
538 538
 	ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion)
539
-	req := httptest.NewRequest(http.MethodDelete, "/volumes/inuse", nil)
539
+	req := httptest.NewRequest(http.MethodDelete, "/volumes/inuse", http.NoBody)
540 540
 	resp := httptest.NewRecorder()
541 541
 
542 542
 	err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "inuse"})
... ...
@@ -564,7 +564,7 @@ func TestVolumeRemoveSwarmForce(t *testing.T) {
564 564
 	}
565 565
 
566 566
 	ctx := context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion)
567
-	req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", nil)
567
+	req := httptest.NewRequest(http.MethodDelete, "/volumes/vol1", http.NoBody)
568 568
 	resp := httptest.NewRecorder()
569 569
 
570 570
 	err := v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"})
... ...
@@ -573,7 +573,7 @@ func TestVolumeRemoveSwarmForce(t *testing.T) {
573 573
 	assert.Assert(t, cerrdefs.IsConflict(err))
574 574
 
575 575
 	ctx = context.WithValue(context.Background(), httputils.APIVersionKey{}, clusterVolumesVersion)
576
-	req = httptest.NewRequest(http.MethodDelete, "/volumes/vol1?force=1", nil)
576
+	req = httptest.NewRequest(http.MethodDelete, "/volumes/vol1?force=1", http.NoBody)
577 577
 	resp = httptest.NewRecorder()
578 578
 
579 579
 	err = v.deleteVolumes(ctx, resp, req, map[string]string{"name": "vol1"})
... ...
@@ -21,7 +21,7 @@ func TestMiddlewares(t *testing.T) {
21 21
 	}
22 22
 	srv.UseMiddleware(*m)
23 23
 
24
-	req, _ := http.NewRequest(http.MethodGet, "/containers/json", nil)
24
+	req, _ := http.NewRequest(http.MethodGet, "/containers/json", http.NoBody)
25 25
 	resp := httptest.NewRecorder()
26 26
 	ctx := context.Background()
27 27
 
... ...
@@ -525,7 +525,7 @@ func TestClientRedirect(t *testing.T) {
525 525
 
526 526
 	for _, tc := range tests {
527 527
 		t.Run(tc.httpMethod, func(t *testing.T) {
528
-			req, err := http.NewRequest(tc.httpMethod, "/redirectme", nil)
528
+			req, err := http.NewRequest(tc.httpMethod, "/redirectme", http.NoBody)
529 529
 			assert.NilError(t, err)
530 530
 			resp, err := client.Do(req)
531 531
 			assert.Check(t, is.Equal(resp.StatusCode, tc.statusCode))
... ...
@@ -40,7 +40,7 @@ func (cli *Client) postHijacked(ctx context.Context, path string, query url.Valu
40 40
 
41 41
 // DialHijack returns a hijacked connection with negotiated protocol proto.
42 42
 func (cli *Client) DialHijack(ctx context.Context, url, proto string, meta map[string][]string) (net.Conn, error) {
43
-	req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, nil)
43
+	req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, http.NoBody)
44 44
 	if err != nil {
45 45
 		return nil, err
46 46
 	}
... ...
@@ -603,7 +603,7 @@ func parseURL(info logger.Info) (*url.URL, error) {
603 603
 }
604 604
 
605 605
 func verifySplunkConnection(l *splunkLogger) error {
606
-	req, err := http.NewRequest(http.MethodOptions, l.url, nil)
606
+	req, err := http.NewRequest(http.MethodOptions, l.url, http.NoBody)
607 607
 	if err != nil {
608 608
 		return err
609 609
 	}
... ...
@@ -103,7 +103,7 @@ func TestNewWithProxy(t *testing.T) {
103 103
 	proxyFunc := splunkLogger.transport.Proxy
104 104
 	assert.Assert(t, proxyFunc != nil)
105 105
 
106
-	req, err := http.NewRequest(http.MethodGet, splunkURL, nil)
106
+	req, err := http.NewRequest(http.MethodGet, splunkURL, http.NoBody)
107 107
 	assert.NilError(t, err)
108 108
 
109 109
 	proxyURL, err := proxyFunc(req)
... ...
@@ -190,7 +190,7 @@ func TestAuthZPluginAPIDenyResponse(t *testing.T) {
190 190
 	socketClient, err := socketHTTPClient(daemonURL)
191 191
 	assert.NilError(t, err)
192 192
 
193
-	req, err := http.NewRequestWithContext(ctx, http.MethodGet, "/version", nil)
193
+	req, err := http.NewRequestWithContext(ctx, http.MethodGet, "/version", http.NoBody)
194 194
 	assert.NilError(t, err)
195 195
 	req.URL.Scheme = "http"
196 196
 	req.URL.Host = client.DummyHost
... ...
@@ -486,7 +486,7 @@ func TestAuthZPluginHeader(t *testing.T) {
486 486
 	socketClient, err := socketHTTPClient(daemonURL)
487 487
 	assert.NilError(t, err)
488 488
 
489
-	req, err := http.NewRequestWithContext(ctx, http.MethodGet, "/version", nil)
489
+	req, err := http.NewRequestWithContext(ctx, http.MethodGet, "/version", http.NoBody)
490 490
 	assert.NilError(t, err)
491 491
 	req.URL.Scheme = "http"
492 492
 	req.URL.Host = client.DummyHost
... ...
@@ -46,7 +46,7 @@ func TestPeerCertificateMarshalJSON(t *testing.T) {
46 46
 
47 47
 	certs := []*x509.Certificate{cert}
48 48
 	addr := "www.authz.com/auth"
49
-	req, err := http.NewRequest(http.MethodGet, addr, nil)
49
+	req, err := http.NewRequest(http.MethodGet, addr, http.NoBody)
50 50
 	assert.NilError(t, err)
51 51
 
52 52
 	req.RequestURI = addr
... ...
@@ -33,7 +33,7 @@ func TestMiddlewareWrapHandler(t *testing.T) {
33 33
 	assert.Assert(t, mdHandler != nil)
34 34
 
35 35
 	addr := "www.example.com/auth"
36
-	req, _ := http.NewRequest(http.MethodGet, addr, nil)
36
+	req, _ := http.NewRequest(http.MethodGet, addr, http.NoBody)
37 37
 	req.RequestURI = addr
38 38
 	req.Header.Add("header", "value")
39 39
 
... ...
@@ -70,7 +70,7 @@ func loginV2(ctx context.Context, authConfig *registry.AuthConfig, endpoint APIE
70 70
 	endpointStr := strings.TrimRight(endpoint.URL.String(), "/") + "/v2/"
71 71
 	log.G(ctx).WithField("endpoint", endpointStr).Debug("attempting v2 login to registry endpoint")
72 72
 
73
-	req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpointStr, nil)
73
+	req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpointStr, http.NoBody)
74 74
 	if err != nil {
75 75
 		return "", err
76 76
 	}
... ...
@@ -181,7 +181,7 @@ func PingV2Registry(endpoint *url.URL, transport http.RoundTripper) (challenge.M
181 181
 		Timeout:   15 * time.Second,
182 182
 	}
183 183
 	endpointStr := strings.TrimRight(endpoint.String(), "/") + "/v2/"
184
-	req, err := http.NewRequest(http.MethodGet, endpointStr, nil)
184
+	req, err := http.NewRequest(http.MethodGet, endpointStr, http.NoBody)
185 185
 	if err != nil {
186 186
 		return nil, err
187 187
 	}
... ...
@@ -22,7 +22,7 @@ func TestResumableRequestHeaderSimpleErrors(t *testing.T) {
22 22
 	client := &http.Client{}
23 23
 
24 24
 	var req *http.Request
25
-	req, err := http.NewRequest(http.MethodGet, ts.URL, nil)
25
+	req, err := http.NewRequest(http.MethodGet, ts.URL, http.NoBody)
26 26
 	assert.NilError(t, err)
27 27
 
28 28
 	resreq := &requestReader{}
... ...
@@ -43,7 +43,7 @@ func TestResumableRequestHeaderNotTooMuchFailures(t *testing.T) {
43 43
 	client := &http.Client{}
44 44
 
45 45
 	var badReq *http.Request
46
-	badReq, err := http.NewRequest(http.MethodGet, "I'm not an url", nil)
46
+	badReq, err := http.NewRequest(http.MethodGet, "I'm not an url", http.NoBody)
47 47
 	assert.NilError(t, err)
48 48
 
49 49
 	resreq := &requestReader{
... ...
@@ -63,7 +63,7 @@ func TestResumableRequestHeaderTooMuchFailures(t *testing.T) {
63 63
 	client := &http.Client{}
64 64
 
65 65
 	var badReq *http.Request
66
-	badReq, err := http.NewRequest(http.MethodGet, "I'm not an url", nil)
66
+	badReq, err := http.NewRequest(http.MethodGet, "I'm not an url", http.NoBody)
67 67
 	assert.NilError(t, err)
68 68
 
69 69
 	resreq := &requestReader{
... ...
@@ -92,7 +92,7 @@ func (errorReaderCloser) Read(p []byte) (int, error) {
92 92
 // If an unknown error is encountered, return 0, nil and log it
93 93
 func TestResumableRequestReaderWithReadError(t *testing.T) {
94 94
 	var req *http.Request
95
-	req, err := http.NewRequest(http.MethodGet, "", nil)
95
+	req, err := http.NewRequest(http.MethodGet, "", http.NoBody)
96 96
 	assert.NilError(t, err)
97 97
 
98 98
 	client := &http.Client{}
... ...
@@ -123,7 +123,7 @@ func TestResumableRequestReaderWithReadError(t *testing.T) {
123 123
 
124 124
 func TestResumableRequestReaderWithEOFWith416Response(t *testing.T) {
125 125
 	var req *http.Request
126
-	req, err := http.NewRequest(http.MethodGet, "", nil)
126
+	req, err := http.NewRequest(http.MethodGet, "", http.NoBody)
127 127
 	assert.NilError(t, err)
128 128
 
129 129
 	client := &http.Client{}
... ...
@@ -159,7 +159,7 @@ func TestResumableRequestReaderWithServerDoesntSupportByteRanges(t *testing.T) {
159 159
 	defer ts.Close()
160 160
 
161 161
 	var req *http.Request
162
-	req, err := http.NewRequest(http.MethodGet, ts.URL, nil)
162
+	req, err := http.NewRequest(http.MethodGet, ts.URL, http.NoBody)
163 163
 	assert.NilError(t, err)
164 164
 
165 165
 	client := &http.Client{}
... ...
@@ -185,7 +185,7 @@ func TestResumableRequestReaderWithZeroTotalSize(t *testing.T) {
185 185
 	defer ts.Close()
186 186
 
187 187
 	var req *http.Request
188
-	req, err := http.NewRequest(http.MethodGet, ts.URL, nil)
188
+	req, err := http.NewRequest(http.MethodGet, ts.URL, http.NoBody)
189 189
 	assert.NilError(t, err)
190 190
 
191 191
 	client := &http.Client{}
... ...
@@ -210,7 +210,7 @@ func TestResumableRequestReader(t *testing.T) {
210 210
 	defer ts.Close()
211 211
 
212 212
 	var req *http.Request
213
-	req, err := http.NewRequest(http.MethodGet, ts.URL, nil)
213
+	req, err := http.NewRequest(http.MethodGet, ts.URL, http.NoBody)
214 214
 	assert.NilError(t, err)
215 215
 
216 216
 	client := &http.Client{}
... ...
@@ -236,7 +236,7 @@ func TestResumableRequestReaderWithInitialResponse(t *testing.T) {
236 236
 	defer ts.Close()
237 237
 
238 238
 	var req *http.Request
239
-	req, err := http.NewRequest(http.MethodGet, ts.URL, nil)
239
+	req, err := http.NewRequest(http.MethodGet, ts.URL, http.NoBody)
240 240
 	assert.NilError(t, err)
241 241
 
242 242
 	client := &http.Client{}
... ...
@@ -122,7 +122,7 @@ func (e *v1Endpoint) ping(ctx context.Context) (v1PingResult, error) {
122 122
 
123 123
 	pingURL := e.String() + "_ping"
124 124
 	log.G(ctx).WithField("url", pingURL).Debug("attempting v1 ping for registry endpoint")
125
-	req, err := http.NewRequestWithContext(ctx, http.MethodGet, pingURL, nil)
125
+	req, err := http.NewRequestWithContext(ctx, http.MethodGet, pingURL, http.NoBody)
126 126
 	if err != nil {
127 127
 		return v1PingResult{}, invalidParam(err)
128 128
 	}
... ...
@@ -175,12 +175,12 @@ func TestV1EndpointValidate(t *testing.T) {
175 175
 
176 176
 func TestTrustedLocation(t *testing.T) {
177 177
 	for _, u := range []string{"http://example.com", "https://example.com:7777", "http://docker.io", "http://test.docker.com", "https://fakedocker.com"} {
178
-		req, _ := http.NewRequest(http.MethodGet, u, nil)
178
+		req, _ := http.NewRequest(http.MethodGet, u, http.NoBody)
179 179
 		assert.Check(t, !trustedLocation(req))
180 180
 	}
181 181
 
182 182
 	for _, u := range []string{"https://docker.io", "https://test.docker.com:80"} {
183
-		req, _ := http.NewRequest(http.MethodGet, u, nil)
183
+		req, _ := http.NewRequest(http.MethodGet, u, http.NoBody)
184 184
 		assert.Check(t, trustedLocation(req))
185 185
 	}
186 186
 }
... ...
@@ -191,10 +191,10 @@ func TestAddRequiredHeadersToRedirectedRequests(t *testing.T) {
191 191
 		{"https://foo.docker.io:7777", "http://bar.docker.com"},
192 192
 		{"https://foo.docker.io", "https://example.com"},
193 193
 	} {
194
-		reqFrom, _ := http.NewRequest(http.MethodGet, urls[0], nil)
194
+		reqFrom, _ := http.NewRequest(http.MethodGet, urls[0], http.NoBody)
195 195
 		reqFrom.Header.Add("Content-Type", "application/json")
196 196
 		reqFrom.Header.Add("Authorization", "super_secret")
197
-		reqTo, _ := http.NewRequest(http.MethodGet, urls[1], nil)
197
+		reqTo, _ := http.NewRequest(http.MethodGet, urls[1], http.NoBody)
198 198
 
199 199
 		_ = addRequiredHeadersToRedirectedRequests(reqTo, []*http.Request{reqFrom})
200 200
 
... ...
@@ -215,10 +215,10 @@ func TestAddRequiredHeadersToRedirectedRequests(t *testing.T) {
215 215
 		{"https://docker.io", "https://docker.com"},
216 216
 		{"https://foo.docker.io:7777", "https://bar.docker.com"},
217 217
 	} {
218
-		reqFrom, _ := http.NewRequest(http.MethodGet, urls[0], nil)
218
+		reqFrom, _ := http.NewRequest(http.MethodGet, urls[0], http.NoBody)
219 219
 		reqFrom.Header.Add("Content-Type", "application/json")
220 220
 		reqFrom.Header.Add("Authorization", "super_secret")
221
-		reqTo, _ := http.NewRequest(http.MethodGet, urls[1], nil)
221
+		reqTo, _ := http.NewRequest(http.MethodGet, urls[1], http.NoBody)
222 222
 
223 223
 		_ = addRequiredHeadersToRedirectedRequests(reqTo, []*http.Request{reqFrom})
224 224
 
... ...
@@ -222,7 +222,7 @@ func (r *session) searchRepositories(ctx context.Context, term string, limit int
222 222
 	u := r.indexEndpoint.String() + "search?q=" + url.QueryEscape(term) + "&n=" + url.QueryEscape(fmt.Sprintf("%d", limit))
223 223
 	log.G(ctx).WithField("url", u).Debug("searchRepositories")
224 224
 
225
-	req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
225
+	req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, http.NoBody)
226 226
 	if err != nil {
227 227
 		return nil, invalidParamWrapf(err, "error building request")
228 228
 	}
... ...
@@ -572,7 +572,7 @@ func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error {
572 572
 		Transport: clientConfig.transport,
573 573
 	}
574 574
 
575
-	req, err := http.NewRequest(http.MethodGet, "/_ping", nil)
575
+	req, err := http.NewRequest(http.MethodGet, "/_ping", http.NoBody)
576 576
 	if err != nil {
577 577
 		return errors.Wrapf(err, "[%s] could not create new request", d.id)
578 578
 	}
... ...
@@ -947,7 +947,7 @@ func (d *Daemon) queryRootDir() (string, error) {
947 947
 		Transport: clientConfig.transport,
948 948
 	}
949 949
 
950
-	req, err := http.NewRequest(http.MethodGet, "/info", nil)
950
+	req, err := http.NewRequest(http.MethodGet, "/info", http.NoBody)
951 951
 	if err != nil {
952 952
 		return "", err
953 953
 	}
... ...
@@ -117,7 +117,7 @@ func newRequest(endpoint string, opts *Options) (*http.Request, error) {
117 117
 	if err != nil {
118 118
 		return nil, errors.Wrapf(err, "failed parsing url %q", opts.host)
119 119
 	}
120
-	req, err := http.NewRequest(http.MethodGet, endpoint, nil)
120
+	req, err := http.NewRequest(http.MethodGet, endpoint, http.NoBody)
121 121
 	if err != nil {
122 122
 		return nil, errors.Wrap(err, "failed to create request")
123 123
 	}