concourse / concourse

Use http.NoBody instead of nil in http.NewRequest calls GO-R4001
Anti-pattern
Major
5 months agoa year old
http.NoBody should be preferred to the nil request body
25}
26
27func doRequest(ctx context.Context, url string) error {
28	req, err := http.NewRequest("GET", url, nil)29	if err != nil {
30		return err
31	}
http.NoBody should be preferred to the nil request body
1264				Expect(err).NotTo(HaveOccurred())
1265
1266				streamInP2pURL := fmt.Sprintf("%s/volumes/%s/stream-in?path=dest-path", otherWorker.URL, myVolume.Handle)
1267				streamP2pOutRequest, _ := http.NewRequest("PUT", fmt.Sprintf("/volumes/%s/stream-p2p-out?path=%s&streamInURL=%s&encoding=%s", myVolume.Handle, "some-dir", streamInP2pURL, encoding), nil)1268				streamP2pOutRecorder := httptest.NewRecorder()
1269				handler.ServeHTTP(streamP2pOutRecorder, streamP2pOutRequest)
1270				Expect(streamP2pOutRecorder.Code).To(Equal(200))
http.NoBody should be preferred to the nil request body
1216				Expect(err).ToNot(HaveOccurred())
1217
1218				streamInP2pURL := fmt.Sprintf("%s/volumes/%s/stream-in?path=dest-path", otherWorker.URL, myVolume.Handle)
1219				streamP2pOutRequest, _ := http.NewRequest(1220					"PUT",
1221					fmt.Sprintf("/volumes/%s/stream-p2p-out?path=%s&streamInURL=%s&encoding=%s",
1222						myVolume.Handle, "some-file", streamInP2pURL, encoding),
http.NoBody should be preferred to the nil request body
1199
1200		It("returns an error when source path is invalid", func() {
1201			streamInP2pURL := fmt.Sprintf("%s/volumes/%s/stream-in?path=dest-path", otherWorker.URL, myVolume.Handle)
1202			request, _ := http.NewRequest("PUT", fmt.Sprintf("/volumes/%s/stream-p2p-out?path=%s&streamInURL=%s&encoding=gzip", myVolume.Handle, "bogus-path", streamInP2pURL), nil)1203			request.Header.Set("Accept-Encoding", string(baggageclaim.GzipEncoding))
1204			recorder := httptest.NewRecorder()
1205			handler.ServeHTTP(recorder, request)
http.NoBody should be preferred to the nil request body
1150				Expect(err).NotTo(HaveOccurred())
1151
1152				recorder = httptest.NewRecorder()
1153				request, err = http.NewRequest("DELETE", "/volumes-async/"+volumeFuture.Handle, nil)1154				Expect(err).NotTo(HaveOccurred())
1155
1156				handler.ServeHTTP(recorder, request)