Skip to content

Commit

Permalink
Drop usage of deprecated ioutil pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
mccutchen committed Oct 17, 2022
1 parent e43229f commit a92e91d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
14 changes: 7 additions & 7 deletions httpbin/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"math/rand"
"mime/multipart"
Expand Down Expand Up @@ -40,7 +40,7 @@ var app = New(
WithDefaultParams(testDefaultParams),
WithMaxBodySize(maxBodySize),
WithMaxDuration(maxDuration),
WithObserver(StdLogObserver(log.New(ioutil.Discard, "", 0))),
WithObserver(StdLogObserver(log.New(io.Discard, "", 0))),
)

var handler = app.Handler()
Expand Down Expand Up @@ -1489,7 +1489,7 @@ func TestGzip(t *testing.T) {
t.Fatalf("error creating gzip reader: %s", err)
}

unzippedBody, err := ioutil.ReadAll(gzipReader)
unzippedBody, err := io.ReadAll(gzipReader)
if err != nil {
t.Fatalf("error reading gzipped body: %s", err)
}
Expand Down Expand Up @@ -1533,7 +1533,7 @@ func TestDeflate(t *testing.T) {
if err != nil {
t.Fatal(err)
}
body, err := ioutil.ReadAll(reader)
body, err := io.ReadAll(reader)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1805,7 +1805,7 @@ func TestDrip(t *testing.T) {
}
defer resp.Body.Close()

body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("error reading response body: %s", err)
}
Expand All @@ -1829,7 +1829,7 @@ func TestDrip(t *testing.T) {
}

// 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 {
t.Fatal("expected timeout reading body")
}
Expand Down Expand Up @@ -1892,7 +1892,7 @@ func TestDrip(t *testing.T) {
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("error reading response body: %s", err)
}
Expand Down
5 changes: 2 additions & 3 deletions httpbin/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net/http"
"net/url"
Expand Down Expand Up @@ -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
// how to handle the content type
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
r.Body.Close()
return err
Expand All @@ -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
// an io.Reader for further processing below
r.Body.Close()
r.Body = ioutil.NopCloser(bytes.NewBuffer(body))
r.Body = io.NopCloser(bytes.NewBuffer(body))

ct := r.Header.Get("Content-Type")
switch {
Expand Down

0 comments on commit a92e91d

Please sign in to comment.