Skip to content
Snippets Groups Projects
Commit a92e91da authored by Will McCutchen's avatar Will McCutchen
Browse files

Drop usage of deprecated ioutil pkg

parent e43229f2
Branches
Tags v2.4.2
No related merge requests found
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"log" "log"
"math/rand" "math/rand"
"mime/multipart" "mime/multipart"
...@@ -40,7 +40,7 @@ var app = New( ...@@ -40,7 +40,7 @@ var app = New(
WithDefaultParams(testDefaultParams), WithDefaultParams(testDefaultParams),
WithMaxBodySize(maxBodySize), WithMaxBodySize(maxBodySize),
WithMaxDuration(maxDuration), WithMaxDuration(maxDuration),
WithObserver(StdLogObserver(log.New(ioutil.Discard, "", 0))), WithObserver(StdLogObserver(log.New(io.Discard, "", 0))),
) )
var handler = app.Handler() var handler = app.Handler()
...@@ -1489,7 +1489,7 @@ func TestGzip(t *testing.T) { ...@@ -1489,7 +1489,7 @@ func TestGzip(t *testing.T) {
t.Fatalf("error creating gzip reader: %s", err) t.Fatalf("error creating gzip reader: %s", err)
} }
unzippedBody, err := ioutil.ReadAll(gzipReader) unzippedBody, err := io.ReadAll(gzipReader)
if err != nil { if err != nil {
t.Fatalf("error reading gzipped body: %s", err) t.Fatalf("error reading gzipped body: %s", err)
} }
...@@ -1533,7 +1533,7 @@ func TestDeflate(t *testing.T) { ...@@ -1533,7 +1533,7 @@ func TestDeflate(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
body, err := ioutil.ReadAll(reader) body, err := io.ReadAll(reader)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -1805,7 +1805,7 @@ func TestDrip(t *testing.T) { ...@@ -1805,7 +1805,7 @@ func TestDrip(t *testing.T) {
} }
defer resp.Body.Close() defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body) body, _ := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatalf("error reading response body: %s", err) t.Fatalf("error reading response body: %s", err)
} }
...@@ -1829,7 +1829,7 @@ func TestDrip(t *testing.T) { ...@@ -1829,7 +1829,7 @@ func TestDrip(t *testing.T) {
} }
// in this case, the timeout happens while trying to read the body // in this case, the timeout happens while trying to read the body
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err == nil { if err == nil {
t.Fatal("expected timeout reading body") t.Fatal("expected timeout reading body")
} }
...@@ -1892,7 +1892,7 @@ func TestDrip(t *testing.T) { ...@@ -1892,7 +1892,7 @@ func TestDrip(t *testing.T) {
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatalf("error reading response body: %s", err) t.Fatalf("error reading response body: %s", err)
} }
......
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math/rand" "math/rand"
"net/http" "net/http"
"net/url" "net/url"
...@@ -109,7 +108,7 @@ func parseBody(w http.ResponseWriter, r *http.Request, resp *bodyResponse) error ...@@ -109,7 +108,7 @@ func parseBody(w http.ResponseWriter, r *http.Request, resp *bodyResponse) error
// Always set resp.Data to the incoming request body, in case we don't know // Always set resp.Data to the incoming request body, in case we don't know
// how to handle the content type // how to handle the content type
body, err := ioutil.ReadAll(r.Body) body, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
r.Body.Close() r.Body.Close()
return err return err
...@@ -119,7 +118,7 @@ func parseBody(w http.ResponseWriter, r *http.Request, resp *bodyResponse) error ...@@ -119,7 +118,7 @@ func parseBody(w http.ResponseWriter, r *http.Request, resp *bodyResponse) error
// After reading the body to populate resp.Data, we need to re-wrap it in // After reading the body to populate resp.Data, we need to re-wrap it in
// an io.Reader for further processing below // an io.Reader for further processing below
r.Body.Close() r.Body.Close()
r.Body = ioutil.NopCloser(bytes.NewBuffer(body)) r.Body = io.NopCloser(bytes.NewBuffer(body))
ct := r.Header.Get("Content-Type") ct := r.Header.Get("Content-Type")
switch { switch {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment