Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace http.NewRequest nil body for http.NoBody. #611

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions proxy/http_response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestNopHTTPResponseParser(t *testing.T) {
w.Header().Set("header1", "value1")
w.Write([]byte("some nice, interesting and long content"))
}
req, _ := http.NewRequest("GET", "/url", nil)
req, _ := http.NewRequest("GET", "/url", http.NoBody)
handler(w, req)
result, err := NoOpHTTPResponseParser(context.Background(), w.Result())
if err != nil {
Expand Down Expand Up @@ -60,7 +60,7 @@ func TestDefaultHTTPResponseParser_gzipped(t *testing.T) {
gzipWriter.Write([]byte(`{"msg":"some nice, interesting and long content"}`))
gzipWriter.Flush()
}
req, _ := http.NewRequest("GET", "/url", nil)
req, _ := http.NewRequest("GET", "/url", http.NoBody)
req.Header.Add("Accept-Encoding", "gzip")
handler(w, req)

Expand Down Expand Up @@ -90,7 +90,7 @@ func TestDefaultHTTPResponseParser_plain(t *testing.T) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Write([]byte(`{"msg":"some nice, interesting and long content"}`))
}
req, _ := http.NewRequest("GET", "/url", nil)
req, _ := http.NewRequest("GET", "/url", http.NoBody)
handler(w, req)

result, err := DefaultHTTPResponseParserFactory(HTTPResponseParserConfig{
Expand Down
8 changes: 4 additions & 4 deletions router/chi/endpoint_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func BenchmarkEndpointHandler_ko(b *testing.B) {
router := chi.NewRouter()
router.Handle("/_chi_endpoint/", NewEndpointHandler(endpoint, p))

req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_chi_endpoint/a?b=1", nil)
req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_chi_endpoint/a?b=1", http.NoBody)
req.Header.Set("Content-Type", "application/json")

b.ReportAllocs()
Expand Down Expand Up @@ -59,7 +59,7 @@ func BenchmarkEndpointHandler_ok(b *testing.B) {
router := chi.NewRouter()
router.Handle("/_chi_endpoint/", NewEndpointHandler(endpoint, p))

req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_chi_endpoint/a?b=1", nil)
req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_chi_endpoint/a?b=1", http.NoBody)
req.Header.Set("Content-Type", "application/json")

b.ReportAllocs()
Expand All @@ -82,7 +82,7 @@ func BenchmarkEndpointHandler_ko_Parallel(b *testing.B) {
router := chi.NewRouter()
router.Handle("/_chi_endpoint/", NewEndpointHandler(endpoint, p))

req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_chi_endpoint/a?b=1", nil)
req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_chi_endpoint/a?b=1", http.NoBody)
req.Header.Set("Content-Type", "application/json")

b.ReportAllocs()
Expand Down Expand Up @@ -113,7 +113,7 @@ func BenchmarkEndpointHandler_ok_Parallel(b *testing.B) {
router := chi.NewRouter()
router.Handle("/_chi_endpoint/", NewEndpointHandler(endpoint, p))

req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_chi_endpoint/a?b=1", nil)
req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_chi_endpoint/a?b=1", http.NoBody)
req.Header.Set("Content-Type", "application/json")

b.ReportAllocs()
Expand Down
6 changes: 3 additions & 3 deletions router/chi/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestDefaultFactory_ok(t *testing.T) {
time.Sleep(5 * time.Millisecond)

for _, endpoint := range serviceCfg.Endpoints {
req, _ := http.NewRequest(strings.ToTitle(endpoint.Method), fmt.Sprintf("http://127.0.0.1:8062%s", endpoint.Endpoint), nil)
req, _ := http.NewRequest(strings.ToTitle(endpoint.Method), fmt.Sprintf("http://127.0.0.1:8062%s", endpoint.Endpoint), http.NoBody)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
Expand Down Expand Up @@ -195,7 +195,7 @@ func TestDefaultFactory_ko(t *testing.T) {
{"GET", "empty"},
{"PUT", "also-ignored"},
} {
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8063/%s", subject[1]), nil)
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8063/%s", subject[1]), http.NoBody)
req.Header.Set("Content-Type", "application/json")
checkResponseIs404(t, req)
}
Expand Down Expand Up @@ -237,7 +237,7 @@ func TestDefaultFactory_proxyFactoryCrash(t *testing.T) {
time.Sleep(5 * time.Millisecond)

for _, subject := range [][]string{{"GET", "ignored"}, {"PUT", "also-ignored"}} {
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8064/%s", subject[1]), nil)
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8064/%s", subject[1]), http.NoBody)
req.Header.Set("Content-Type", "application/json")
checkResponseIs404(t, req)
}
Expand Down
8 changes: 4 additions & 4 deletions router/gin/endpoint_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func BenchmarkEndpointHandler_ko(b *testing.B) {
router := gin.New()
router.GET("/_gin_endpoint/:param", EndpointHandler(endpoint, p))

req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_gin_endpoint/a?b=1", nil)
req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_gin_endpoint/a?b=1", http.NoBody)
req.Header.Set("Content-Type", "application/json")

b.ReportAllocs()
Expand Down Expand Up @@ -61,7 +61,7 @@ func BenchmarkEndpointHandler_ok(b *testing.B) {
router := gin.New()
router.GET("/_gin_endpoint/:param", EndpointHandler(endpoint, p))

req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_gin_endpoint/a?b=1", nil)
req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_gin_endpoint/a?b=1", http.NoBody)
req.Header.Set("Content-Type", "application/json")

b.ReportAllocs()
Expand All @@ -85,7 +85,7 @@ func BenchmarkEndpointHandler_ko_Parallel(b *testing.B) {
router := gin.New()
router.GET("/_gin_endpoint/:param", EndpointHandler(endpoint, p))

req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_gin_endpoint/a?b=1", nil)
req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_gin_endpoint/a?b=1", http.NoBody)
req.Header.Set("Content-Type", "application/json")

b.ReportAllocs()
Expand Down Expand Up @@ -117,7 +117,7 @@ func BenchmarkEndpointHandler_ok_Parallel(b *testing.B) {
router := gin.New()
router.GET("/_gin_endpoint/:param", EndpointHandler(endpoint, p))

req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_gin_endpoint/a?b=1", nil)
req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_gin_endpoint/a?b=1", http.NoBody)
req.Header.Set("Content-Type", "application/json")

b.ReportAllocs()
Expand Down
8 changes: 4 additions & 4 deletions router/gin/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestDefaultFactory_ok(t *testing.T) {
time.Sleep(5 * time.Millisecond)

for _, endpoint := range serviceCfg.Endpoints {
req, _ := http.NewRequest(strings.ToTitle(endpoint.Method), fmt.Sprintf("http://127.0.0.1:8072%s", endpoint.Endpoint), nil)
req, _ := http.NewRequest(strings.ToTitle(endpoint.Method), fmt.Sprintf("http://127.0.0.1:8072%s", endpoint.Endpoint), http.NoBody)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestDefaultFactory_ok(t *testing.T) {
}
}

req, _ := http.NewRequest("OPTIONS", "http://127.0.0.1:8072/some", nil)
req, _ := http.NewRequest("OPTIONS", "http://127.0.0.1:8072/some", http.NoBody)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestDefaultFactory_ko(t *testing.T) {
{"GET", "empty"},
{"PUT", "also-ignored"},
} {
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8073/%s", subject[1]), nil)
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8073/%s", subject[1]), http.NoBody)
req.Header.Set("Content-Type", "application/json")
checkResponseIs404(t, req)
}
Expand Down Expand Up @@ -239,7 +239,7 @@ func TestDefaultFactory_proxyFactoryCrash(t *testing.T) {
time.Sleep(5 * time.Millisecond)

for _, subject := range [][]string{{"GET", "ignored"}, {"PUT", "also-ignored"}} {
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8074/%s", subject[1]), nil)
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8074/%s", subject[1]), http.NoBody)
req.Header.Set("Content-Type", "application/json")
checkResponseIs404(t, req)
}
Expand Down
6 changes: 3 additions & 3 deletions router/gorilla/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestDefaultFactory_ok(t *testing.T) {
time.Sleep(5 * time.Millisecond)

for _, endpoint := range serviceCfg.Endpoints {
req, _ := http.NewRequest(endpoint.Method, fmt.Sprintf("http://127.0.0.1:8082%s", endpoint.Endpoint), nil)
req, _ := http.NewRequest(endpoint.Method, fmt.Sprintf("http://127.0.0.1:8082%s", endpoint.Endpoint), http.NoBody)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestDefaultFactory_ko(t *testing.T) {
{"GET", "empty"},
{"PUT", "also-ignored"},
} {
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8083/%s", subject[1]), nil)
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8083/%s", subject[1]), http.NoBody)
req.Header.Set("Content-Type", "application/json")
checkResponseIs404(t, req)
}
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestDefaultFactory_proxyFactoryCrash(t *testing.T) {
time.Sleep(5 * time.Millisecond)

for _, subject := range [][]string{{"GET", "ignored"}, {"PUT", "also-ignored"}} {
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8084/%s", subject[1]), nil)
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8084/%s", subject[1]), http.NoBody)
req.Header.Set("Content-Type", "application/json")
checkResponseIs404(t, req)
}
Expand Down
6 changes: 3 additions & 3 deletions router/httptreemux/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestDefaultFactory_ok(t *testing.T) {
<-time.After(5 * time.Millisecond)

for _, endpoint := range serviceCfg.Endpoints {
req, _ := http.NewRequest(endpoint.Method, fmt.Sprintf("http://127.0.0.1:8082%s", endpoint.Endpoint), nil)
req, _ := http.NewRequest(endpoint.Method, fmt.Sprintf("http://127.0.0.1:8082%s", endpoint.Endpoint), http.NoBody)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestDefaultFactory_ko(t *testing.T) {
{"GET", "empty"},
{"PUT", "also-ignored"},
} {
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8083/%s", subject[1]), nil)
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8083/%s", subject[1]), http.NoBody)
req.Header.Set("Content-Type", "application/json")
checkResponseIs404(t, req)
}
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestDefaultFactory_proxyFactoryCrash(t *testing.T) {
time.Sleep(5 * time.Millisecond)

for _, subject := range [][]string{{"GET", "ignored"}, {"PUT", "also-ignored"}} {
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8084/%s", subject[1]), nil)
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8084/%s", subject[1]), http.NoBody)
req.Header.Set("Content-Type", "application/json")
checkResponseIs404(t, req)
}
Expand Down
8 changes: 4 additions & 4 deletions router/mux/endpoint_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func BenchmarkEndpointHandler_ko(b *testing.B) {
router := http.NewServeMux()
router.Handle("/_gin_endpoint/", EndpointHandler(endpoint, p))

req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_gin_endpoint/a?b=1", nil)
req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_gin_endpoint/a?b=1", http.NoBody)
req.Header.Set("Content-Type", "application/json")

b.ReportAllocs()
Expand Down Expand Up @@ -58,7 +58,7 @@ func BenchmarkEndpointHandler_ok(b *testing.B) {
router := http.NewServeMux()
router.Handle("/_gin_endpoint/", EndpointHandler(endpoint, p))

req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_gin_endpoint/a?b=1", nil)
req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_gin_endpoint/a?b=1", http.NoBody)
req.Header.Set("Content-Type", "application/json")

b.ReportAllocs()
Expand All @@ -81,7 +81,7 @@ func BenchmarkEndpointHandler_ko_Parallel(b *testing.B) {
router := http.NewServeMux()
router.Handle("/_gin_endpoint/", EndpointHandler(endpoint, p))

req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_gin_endpoint/a?b=1", nil)
req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_gin_endpoint/a?b=1", http.NoBody)
req.Header.Set("Content-Type", "application/json")

b.ReportAllocs()
Expand Down Expand Up @@ -112,7 +112,7 @@ func BenchmarkEndpointHandler_ok_Parallel(b *testing.B) {
router := http.NewServeMux()
router.Handle("/_gin_endpoint/", EndpointHandler(endpoint, p))

req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_gin_endpoint/a?b=1", nil)
req, _ := http.NewRequest("GET", "http://127.0.0.1:8080/_gin_endpoint/a?b=1", http.NoBody)
req.Header.Set("Content-Type", "application/json")

b.ReportAllocs()
Expand Down
6 changes: 3 additions & 3 deletions router/mux/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestDefaultFactory_ok(t *testing.T) {
time.Sleep(5 * time.Millisecond)

for _, endpoint := range serviceCfg.Endpoints {
req, _ := http.NewRequest(strings.ToTitle(endpoint.Method), fmt.Sprintf("http://127.0.0.1:8062%s", endpoint.Endpoint), nil)
req, _ := http.NewRequest(strings.ToTitle(endpoint.Method), fmt.Sprintf("http://127.0.0.1:8062%s", endpoint.Endpoint), http.NoBody)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestDefaultFactory_ko(t *testing.T) {
{"GET", "empty"},
{"PUT", "also-ignored"},
} {
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8063/%s", subject[1]), nil)
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8063/%s", subject[1]), http.NoBody)
req.Header.Set("Content-Type", "application/json")
checkResponseIs404(t, req)
}
Expand Down Expand Up @@ -236,7 +236,7 @@ func TestDefaultFactory_proxyFactoryCrash(t *testing.T) {
time.Sleep(5 * time.Millisecond)

for _, subject := range [][]string{{"GET", "ignored"}, {"PUT", "also-ignored"}} {
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8064/%s", subject[1]), nil)
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8064/%s", subject[1]), http.NoBody)
req.Header.Set("Content-Type", "application/json")
checkResponseIs404(t, req)
}
Expand Down
8 changes: 4 additions & 4 deletions router/negroni/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestDefaultFactory_ok(t *testing.T) {
time.Sleep(5 * time.Millisecond)

for _, endpoint := range serviceCfg.Endpoints {
req, _ := http.NewRequest(endpoint.Method, fmt.Sprintf("http://127.0.0.1:8052%s", endpoint.Endpoint), nil)
req, _ := http.NewRequest(endpoint.Method, fmt.Sprintf("http://127.0.0.1:8052%s", endpoint.Endpoint), http.NoBody)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestDefaultFactory_middlewares(t *testing.T) {
time.Sleep(5 * time.Millisecond)

for _, endpoint := range serviceCfg.Endpoints {
req, _ := http.NewRequest(endpoint.Method, fmt.Sprintf("http://127.0.0.1:8090%s", endpoint.Endpoint), nil)
req, _ := http.NewRequest(endpoint.Method, fmt.Sprintf("http://127.0.0.1:8090%s", endpoint.Endpoint), http.NoBody)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
Expand Down Expand Up @@ -254,7 +254,7 @@ func TestDefaultFactory_ko(t *testing.T) {
{"GET", "empty"},
{"PUT", "also-ignored"},
} {
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8053/%s", subject[1]), nil)
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8053/%s", subject[1]), http.NoBody)
req.Header.Set("Content-Type", "application/json")
checkResponseIs404(t, req)
}
Expand Down Expand Up @@ -296,7 +296,7 @@ func TestDefaultFactory_proxyFactoryCrash(t *testing.T) {
time.Sleep(5 * time.Millisecond)

for _, subject := range [][]string{{"GET", "ignored"}, {"PUT", "also-ignored"}} {
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8054/%s", subject[1]), nil)
req, _ := http.NewRequest(subject[0], fmt.Sprintf("http://127.0.0.1:8054/%s", subject[1]), http.NoBody)
req.Header.Set("Content-Type", "application/json")
checkResponseIs404(t, req)
}
Expand Down
3 changes: 2 additions & 1 deletion transport/http/client/plugin/plugin_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build integration || !race
// +build integration !race

// SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -43,7 +44,7 @@ func TestLoadWithLogger(t *testing.T) {
},
})

req, _ := http.NewRequest("GET", "http://some.example.tld/path", nil)
req, _ := http.NewRequest("GET", "http://some.example.tld/path", http.NoBody)
resp, err := h(context.Background(), req)
if err != nil {
t.Errorf("unexpected error: %s", err.Error())
Expand Down
3 changes: 2 additions & 1 deletion transport/http/server/plugin/plugin_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build integration || !race
// +build integration !race

// SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -53,7 +54,7 @@ func TestLoadWithLogger(t *testing.T) {
return
}

req, _ := http.NewRequest("GET", "http://some.example.tld/path", nil)
req, _ := http.NewRequest("GET", "http://some.example.tld/path", http.NoBody)
w := httptest.NewRecorder()
handler.ServeHTTP(w, req)

Expand Down