From a696949f6c1b7eec6d6529f8e93612e65d0f5ec2 Mon Sep 17 00:00:00 2001 From: Aoang Date: Fri, 16 Sep 2022 03:28:25 +0800 Subject: [PATCH] Deprecate Go 1.15 (#1379) * Dropping support for 1.15. * Replaces Go 1.16 Deprecated functions * Update test build flag * Fix import sort and comment * Update github.com/klauspost/compress to v1.15.9 https://github.com/klauspost/compress improved performance and changed Minimum version is 1.16, this should be the final supported release for Go 1.16 (https://github.com/klauspost/compress/commit/6d0019a95afa3221f7522d1f2eed0033b5e79470) . --- .github/workflows/test.yml | 2 +- allocation_test.go | 1 - brotli_test.go | 4 +- bytesconv_table_gen.go | 3 +- client_timing_test.go | 10 ++--- client_timing_wait_test.go | 7 +--- client_unix_test.go | 5 +-- compress_test.go | 6 +-- fasthttpadaptor/adaptor_test.go | 4 +- fasthttpadaptor/request.go | 4 +- fasthttpproxy/proxy_env.go | 5 +-- fasthttputil/inmemory_listener_test.go | 3 +- fasthttputil/pipeconns_test.go | 3 +- fs.go | 3 +- fs_test.go | 16 +++----- go.mod | 4 +- go.sum | 4 +- http_test.go | 7 ++-- server_test.go | 51 ++++++++++++-------------- server_timing_test.go | 3 +- stackless/writer_test.go | 3 +- stream_test.go | 5 +-- streaming_test.go | 10 ++--- workerpool_test.go | 4 +- 24 files changed, 73 insertions(+), 94 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 73af78bfff..e34b6bdc75 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ jobs: test: strategy: matrix: - go-version: [1.15.x, 1.16.x, 1.17.x, 1.18.x, 1.19.x] + go-version: [1.16.x, 1.17.x, 1.18.x, 1.19.x] os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: diff --git a/allocation_test.go b/allocation_test.go index 5429ab654a..348fef149a 100644 --- a/allocation_test.go +++ b/allocation_test.go @@ -5,7 +5,6 @@ package fasthttp import ( "net" - "testing" ) diff --git a/brotli_test.go b/brotli_test.go index 0d7340a026..4872c6b656 100644 --- a/brotli_test.go +++ b/brotli_test.go @@ -4,7 +4,7 @@ import ( "bufio" "bytes" "fmt" - "io/ioutil" + "io" "testing" ) @@ -91,7 +91,7 @@ func testBrotliCompressSingleCase(s string) error { if err != nil { return fmt.Errorf("unexpected error: %w. s=%q", err, s) } - body, err := ioutil.ReadAll(zr) + body, err := io.ReadAll(zr) if err != nil { return fmt.Errorf("unexpected error: %w. s=%q", err, s) } diff --git a/bytesconv_table_gen.go b/bytesconv_table_gen.go index 134f9dd926..e92136ec72 100644 --- a/bytesconv_table_gen.go +++ b/bytesconv_table_gen.go @@ -6,7 +6,6 @@ package main import ( "bytes" "fmt" - "io/ioutil" "log" ) @@ -107,7 +106,7 @@ func main() { fmt.Fprintf(w, "const quotedArgShouldEscapeTable = %q\n", quotedArgShouldEscapeTable) fmt.Fprintf(w, "const quotedPathShouldEscapeTable = %q\n", quotedPathShouldEscapeTable) - if err := ioutil.WriteFile("bytesconv_table.go", w.Bytes(), 0660); err != nil { + if err := os.WriteFile("bytesconv_table.go", w.Bytes(), 0660); err != nil { log.Fatal(err) } } diff --git a/client_timing_test.go b/client_timing_test.go index ac631cad1f..07551550ae 100644 --- a/client_timing_test.go +++ b/client_timing_test.go @@ -3,7 +3,7 @@ package fasthttp import ( "bytes" "fmt" - "io/ioutil" + "io" "net" "net/http" "runtime" @@ -169,7 +169,7 @@ func BenchmarkNetHTTPClientDoFastServer(b *testing.B) { if resp.StatusCode != http.StatusOK { b.Fatalf("unexpected status code: %d", resp.StatusCode) } - respBody, err := ioutil.ReadAll(resp.Body) + respBody, err := io.ReadAll(resp.Body) resp.Body.Close() if err != nil { b.Fatalf("unexpected error when reading response body: %v", err) @@ -297,7 +297,7 @@ func benchmarkNetHTTPClientGetEndToEndTCP(b *testing.B, parallelism int) { if resp.StatusCode != http.StatusOK { b.Fatalf("unexpected status code: %d. Expecting %d", resp.StatusCode, http.StatusOK) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) resp.Body.Close() if err != nil { b.Fatalf("unexpected error when reading response body: %v", err) @@ -427,7 +427,7 @@ func benchmarkNetHTTPClientGetEndToEndInmemory(b *testing.B, parallelism int) { if resp.StatusCode != http.StatusOK { b.Fatalf("unexpected status code: %d. Expecting %d", resp.StatusCode, http.StatusOK) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) resp.Body.Close() if err != nil { b.Fatalf("unexpected error when reading response body: %v", err) @@ -554,7 +554,7 @@ func benchmarkNetHTTPClientEndToEndBigResponseInmemory(b *testing.B, parallelism if resp.StatusCode != http.StatusOK { b.Fatalf("unexpected status code: %d. Expecting %d", resp.StatusCode, http.StatusOK) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) resp.Body.Close() if err != nil { b.Fatalf("unexpected error when reading response body: %v", err) diff --git a/client_timing_wait_test.go b/client_timing_wait_test.go index 4b2d90ea53..906ec7d597 100644 --- a/client_timing_wait_test.go +++ b/client_timing_wait_test.go @@ -1,10 +1,7 @@ -//go:build go1.11 -// +build go1.11 - package fasthttp import ( - "io/ioutil" + "io" "net" "net/http" "strings" @@ -146,7 +143,7 @@ func benchmarkNetHTTPClientGetEndToEndWaitConnInmemory(b *testing.B, parallelism if resp.StatusCode != http.StatusOK { b.Fatalf("unexpected status code: %d. Expecting %d", resp.StatusCode, http.StatusOK) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) resp.Body.Close() if err != nil { b.Fatalf("unexpected error when reading response body: %v", err) diff --git a/client_unix_test.go b/client_unix_test.go index f369111d5c..380f909eaf 100644 --- a/client_unix_test.go +++ b/client_unix_test.go @@ -5,7 +5,6 @@ package fasthttp import ( "io" - "io/ioutil" "net" "net/http" "strings" @@ -32,7 +31,7 @@ func TestRstConnResponseWhileSending(t *testing.T) { // Read at least one byte of the header // Otherwise we would have an unsolicited response - _, err = ioutil.ReadAll(io.LimitReader(conn, 1)) + _, err = io.ReadAll(io.LimitReader(conn, 1)) if err != nil { t.Error(err) } @@ -94,7 +93,7 @@ func TestRstConnClosedWithoutResponse(t *testing.T) { // Read at least one byte of the header // Otherwise we would have an unsolicited response - _, err = ioutil.ReadAll(io.LimitReader(conn, 1)) + _, err = io.ReadAll(io.LimitReader(conn, 1)) if err != nil { t.Error(err) } diff --git a/compress_test.go b/compress_test.go index 111c93c61a..329f0f5953 100644 --- a/compress_test.go +++ b/compress_test.go @@ -3,7 +3,7 @@ package fasthttp import ( "bytes" "fmt" - "io/ioutil" + "io" "testing" "time" ) @@ -173,7 +173,7 @@ func testGzipCompressSingleCase(s string) error { if err != nil { return fmt.Errorf("unexpected error: %w. s=%q", err, s) } - body, err := ioutil.ReadAll(zr) + body, err := io.ReadAll(zr) if err != nil { return fmt.Errorf("unexpected error: %w. s=%q", err, s) } @@ -196,7 +196,7 @@ func testFlateCompressSingleCase(s string) error { if err != nil { return fmt.Errorf("unexpected error: %w. s=%q", err, s) } - body, err := ioutil.ReadAll(zr) + body, err := io.ReadAll(zr) if err != nil { return fmt.Errorf("unexpected error: %w. s=%q", err, s) } diff --git a/fasthttpadaptor/adaptor_test.go b/fasthttpadaptor/adaptor_test.go index e6d7018dcf..ba23e60bec 100644 --- a/fasthttpadaptor/adaptor_test.go +++ b/fasthttpadaptor/adaptor_test.go @@ -2,7 +2,7 @@ package fasthttpadaptor import ( "fmt" - "io/ioutil" + "io" "net" "net/http" "net/url" @@ -66,7 +66,7 @@ func TestNewFastHTTPHandler(t *testing.T) { if r.RemoteAddr != expectedRemoteAddr { t.Fatalf("unexpected remoteAddr %q. Expecting %q", r.RemoteAddr, expectedRemoteAddr) } - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) r.Body.Close() if err != nil { t.Fatalf("unexpected error when reading request body: %v", err) diff --git a/fasthttpadaptor/request.go b/fasthttpadaptor/request.go index 7a49bfd079..3f499f8cbb 100644 --- a/fasthttpadaptor/request.go +++ b/fasthttpadaptor/request.go @@ -2,7 +2,7 @@ package fasthttpadaptor import ( "bytes" - "io/ioutil" + "io" "net/http" "net/url" @@ -28,7 +28,7 @@ func ConvertRequest(ctx *fasthttp.RequestCtx, r *http.Request, forServer bool) e r.RemoteAddr = ctx.RemoteAddr().String() r.Host = string(ctx.Host()) r.TLS = ctx.TLSConnectionState() - r.Body = ioutil.NopCloser(bytes.NewReader(body)) + r.Body = io.NopCloser(bytes.NewReader(body)) r.URL = rURL if forServer { diff --git a/fasthttpproxy/proxy_env.go b/fasthttpproxy/proxy_env.go index 604724260a..3f91440d16 100644 --- a/fasthttpproxy/proxy_env.go +++ b/fasthttpproxy/proxy_env.go @@ -9,9 +9,8 @@ import ( "sync/atomic" "time" - "golang.org/x/net/http/httpproxy" - "github.com/valyala/fasthttp" + "golang.org/x/net/http/httpproxy" ) const ( @@ -32,7 +31,7 @@ func FasthttpProxyHTTPDialer() fasthttp.DialFunc { return FasthttpProxyHTTPDialerTimeout(0) } -// FasthttpProxyHTTPDialer returns a fasthttp.DialFunc that dials using +// FasthttpProxyHTTPDialerTimeout returns a fasthttp.DialFunc that dials using // the env(HTTP_PROXY, HTTPS_PROXY and NO_PROXY) configured HTTP proxy using the given timeout. // // Example usage: diff --git a/fasthttputil/inmemory_listener_test.go b/fasthttputil/inmemory_listener_test.go index 907a8d0ff6..8a8d16acc9 100644 --- a/fasthttputil/inmemory_listener_test.go +++ b/fasthttputil/inmemory_listener_test.go @@ -5,7 +5,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "net" "net/http" "sync" @@ -147,7 +146,7 @@ func testInmemoryListenerHTTPSingle(t *testing.T, client *http.Client, content s if err != nil { t.Fatalf("unexpected error: %v", err) } - b, err := ioutil.ReadAll(res.Body) + b, err := io.ReadAll(res.Body) if err != nil { t.Fatalf("unexpected error: %v", err) } diff --git a/fasthttputil/pipeconns_test.go b/fasthttputil/pipeconns_test.go index e81b0ad436..f460639be6 100644 --- a/fasthttputil/pipeconns_test.go +++ b/fasthttputil/pipeconns_test.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "net" "testing" "time" @@ -162,7 +161,7 @@ func testPipeConnsCloseWhileReadWrite(t *testing.T) { readCh := make(chan error) go func() { var err error - if _, err = io.Copy(ioutil.Discard, c1); err != nil { + if _, err = io.Copy(io.Discard, c1); err != nil { if err != errConnectionClosed { err = fmt.Errorf("unexpected error: %w", err) } else { diff --git a/fs.go b/fs.go index 1e52c93d43..a8bcd13f9d 100644 --- a/fs.go +++ b/fs.go @@ -6,7 +6,6 @@ import ( "fmt" "html" "io" - "io/ioutil" "mime" "net/http" "os" @@ -1377,7 +1376,7 @@ func readFileHeader(f *os.File, compressed bool, fileEncoding string) ([]byte, e R: r, N: 512, } - data, err := ioutil.ReadAll(lr) + data, err := io.ReadAll(lr) if _, err := f.Seek(0, 0); err != nil { return nil, err } diff --git a/fs_test.go b/fs_test.go index 693d1a4b31..22a9b33c2b 100644 --- a/fs_test.go +++ b/fs_test.go @@ -1,6 +1,3 @@ -// go:build !windows -// Don't run FS tests on windows as it isn't compatible for now. - package fasthttp import ( @@ -8,7 +5,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "math/rand" "os" "path" @@ -158,13 +154,13 @@ func TestServeFileSmallNoReadFrom(t *testing.T) { teststr := "hello, world!" - tempdir, err := ioutil.TempDir("", "httpexpect") + tempdir, err := os.MkdirTemp("", "httpexpect") if err != nil { t.Fatal(err) } defer os.RemoveAll(tempdir) - if err := ioutil.WriteFile( + if err := os.WriteFile( path.Join(tempdir, "hello"), []byte(teststr), 0666); err != nil { t.Fatal(err) } @@ -412,7 +408,7 @@ func getFileContents(path string) ([]byte, error) { return nil, err } defer f.Close() - return ioutil.ReadAll(f) + return io.ReadAll(f) } func TestParseByteRangeSuccess(t *testing.T) { @@ -703,7 +699,7 @@ func fsHandlerTest(t *testing.T, requestHandler RequestHandler, filenames []stri f.Close() continue } - data, err := ioutil.ReadAll(f) + data, err := io.ReadAll(f) f.Close() if err != nil { t.Fatalf("cannot read file contents %q: %v", name, err) @@ -714,7 +710,7 @@ func fsHandlerTest(t *testing.T, requestHandler RequestHandler, filenames []stri if ctx.Response.bodyStream == nil { t.Fatalf("response body stream must be non-empty") } - body, err := ioutil.ReadAll(ctx.Response.bodyStream) + body, err := io.ReadAll(ctx.Response.bodyStream) if err != nil { t.Fatalf("error when reading response body stream: %v", err) } @@ -733,7 +729,7 @@ func fsHandlerTest(t *testing.T, requestHandler RequestHandler, filenames []stri if ctx.Response.bodyStream == nil { t.Fatalf("response body stream must be non-empty") } - body, err := ioutil.ReadAll(ctx.Response.bodyStream) + body, err := io.ReadAll(ctx.Response.bodyStream) if err != nil { t.Fatalf("error when reading response body stream: %v", err) } diff --git a/go.mod b/go.mod index a9cd927af6..2d2b3a90a1 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,10 @@ module github.com/valyala/fasthttp -go 1.15 +go 1.16 require ( github.com/andybalholm/brotli v1.0.4 - github.com/klauspost/compress v1.15.0 + github.com/klauspost/compress v1.15.9 github.com/valyala/bytebufferpool v1.0.0 github.com/valyala/tcplisten v1.0.0 golang.org/x/crypto v0.0.0-20220214200702-86341886e292 diff --git a/go.sum b/go.sum index 381cb8a3cf..b8dbfb76ab 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= -github.com/klauspost/compress v1.15.0 h1:xqfchp4whNFxn5A4XFyyYtitiWI8Hy5EW59jEwcyL6U= -github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= +github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY= +github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= diff --git a/http_test.go b/http_test.go index 071d177b6e..58bc8cb4ff 100644 --- a/http_test.go +++ b/http_test.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math" "mime/multipart" "net/http" @@ -655,7 +654,7 @@ tailfoobar` t.Fatalf("unexpected error: %v", err) } - tail, err := ioutil.ReadAll(br) + tail, err := io.ReadAll(br) if err != nil { t.Fatalf("unexpected error: %v", err) } @@ -1241,7 +1240,7 @@ func TestRequestReadPostNoBody(t *testing.T) { t.Fatalf("unexpected content-length: %d. Expecting 0", r.Header.ContentLength()) } - tail, err := ioutil.ReadAll(br) + tail, err := io.ReadAll(br) if err != nil { t.Fatalf("unexpected error: %v", err) } @@ -1272,7 +1271,7 @@ func TestRequestContinueReadBody(t *testing.T) { t.Fatalf("unexpected body %q. Expecting %q", body, "abcde") } - tail, err := ioutil.ReadAll(br) + tail, err := io.ReadAll(br) if err != nil { t.Fatalf("unexpected error: %v", err) } diff --git a/server_test.go b/server_test.go index 1a2adcc582..af3cd4a81d 100644 --- a/server_test.go +++ b/server_test.go @@ -1,5 +1,3 @@ -// go:build !windows || !race - package fasthttp import ( @@ -10,7 +8,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "mime/multipart" "net" "os" @@ -351,7 +348,7 @@ func TestSaveMultipartFile(t *testing.T) { } defer os.Remove("filea.txt") - if c, err := ioutil.ReadFile("filea.txt"); err != nil { + if c, err := os.ReadFile("filea.txt"); err != nil { t.Fatal(err) } else if string(c) != filea { t.Fatalf("filea changed expected %q got %q", filea, c) @@ -371,7 +368,7 @@ func TestSaveMultipartFile(t *testing.T) { } defer os.Remove("fileb.txt") - if c, err := ioutil.ReadFile("fileb.txt"); err != nil { + if c, err := os.ReadFile("fileb.txt"); err != nil { t.Fatal(err) } else if string(c) != fileb { t.Fatalf("fileb changed expected %q got %q", fileb, c) @@ -394,7 +391,7 @@ func TestServerName(t *testing.T) { t.Fatalf("Unexpected error from serveConn: %v", err) } - resp, err := ioutil.ReadAll(&rw.w) + resp, err := io.ReadAll(&rw.w) if err != nil { t.Fatalf("Unexpected error from ReadAll: %v", err) } @@ -738,7 +735,7 @@ func TestServerResponseBodyStream(t *testing.T) { } close(readyCh) - tail, err := ioutil.ReadAll(br) + tail, err := io.ReadAll(br) if err != nil { t.Errorf("unexpected error: %v", err) } @@ -811,7 +808,7 @@ func TestServerDisableKeepalive(t *testing.T) { } // make sure the connection is closed - data, err := ioutil.ReadAll(br) + data, err := io.ReadAll(br) if err != nil { t.Errorf("unexpected error: %v", err) } @@ -1584,7 +1581,7 @@ func TestServerHTTP10ConnectionKeepAlive(t *testing.T) { tailCh := make(chan struct{}) go func() { - tail, err := ioutil.ReadAll(br) + tail, err := io.ReadAll(br) if err != nil { t.Errorf("error when reading tail: %v", err) } @@ -1659,7 +1656,7 @@ func TestServerHTTP10ConnectionClose(t *testing.T) { tailCh := make(chan struct{}) go func() { - tail, err := ioutil.ReadAll(br) + tail, err := io.ReadAll(br) if err != nil { t.Errorf("error when reading tail: %v", err) } @@ -1795,7 +1792,7 @@ func TestServerHeadRequest(t *testing.T) { t.Fatalf("unexpected content-type %q. Expecting %q", resp.Header.ContentType(), "aaa/bbb") } - data, err := ioutil.ReadAll(br) + data, err := io.ReadAll(br) if err != nil { t.Fatalf("Unexpected error when reading remaining data: %v", err) } @@ -1836,7 +1833,7 @@ func TestServerExpect100Continue(t *testing.T) { br := bufio.NewReader(&rw.w) verifyResponse(t, br, StatusOK, string(defaultContentType), "foobar") - data, err := ioutil.ReadAll(br) + data, err := io.ReadAll(br) if err != nil { t.Fatalf("Unexpected error when reading remaining data: %v", err) } @@ -1892,7 +1889,7 @@ func TestServerContinueHandler(t *testing.T) { br := bufio.NewReader(&rw.w) verifyResponse(t, br, expectedStatusCode, string(defaultContentType), expectedResponse) - data, err := ioutil.ReadAll(br) + data, err := io.ReadAll(br) if err != nil { t.Fatalf("Unexpected error when reading remaining data: %v", err) } @@ -2235,7 +2232,7 @@ func TestServeConnNonHTTP11KeepAlive(t *testing.T) { t.Fatal("expecting Connection: close") } - data, err := ioutil.ReadAll(br) + data, err := io.ReadAll(br) if err != nil { t.Fatalf("Unexpected error when reading remaining data: %v", err) } @@ -2377,7 +2374,7 @@ func TestRequestCtxSendFileModified(t *testing.T) { if err != nil { t.Fatalf("cannot open file: %v", err) } - body, err := ioutil.ReadAll(f) + body, err := io.ReadAll(f) f.Close() if err != nil { t.Fatalf("error when reading file: %v", err) @@ -2420,7 +2417,7 @@ func TestRequestCtxSendFile(t *testing.T) { if err != nil { t.Fatalf("cannot open file: %v", err) } - body, err := ioutil.ReadAll(f) + body, err := io.ReadAll(f) f.Close() if err != nil { t.Fatalf("error when reading file: %v", err) @@ -2521,7 +2518,7 @@ func testRequestCtxHijack(t *testing.T, s *Server) { br := bufio.NewReader(&rw.w) verifyResponse(t, br, StatusOK, "foo/bar", "hijack it!") - data, err := ioutil.ReadAll(br) + data, err := io.ReadAll(br) if err != nil { t.Errorf("[iter: %d] Unexpected error when reading remaining data: %v", id, err) @@ -2884,7 +2881,7 @@ func TestServerTimeoutErrorWithResponse(t *testing.T) { verifyResponse(t, br, 456, "foo/bar", "path=/foo") verifyResponse(t, br, 456, "foo/bar", "path=/bar") - data, err := ioutil.ReadAll(br) + data, err := io.ReadAll(br) if err != nil { t.Fatalf("Unexpected error when reading remaining data: %v", err) } @@ -2918,7 +2915,7 @@ func TestServerTimeoutErrorWithCode(t *testing.T) { verifyResponse(t, br, StatusBadRequest, string(defaultContentType), "stolen ctx") verifyResponse(t, br, StatusBadRequest, string(defaultContentType), "stolen ctx") - data, err := ioutil.ReadAll(br) + data, err := io.ReadAll(br) if err != nil { t.Fatalf("Unexpected error when reading remaining data: %v", err) } @@ -2952,7 +2949,7 @@ func TestServerTimeoutError(t *testing.T) { verifyResponse(t, br, StatusRequestTimeout, string(defaultContentType), "stolen ctx") verifyResponse(t, br, StatusRequestTimeout, string(defaultContentType), "stolen ctx") - data, err := ioutil.ReadAll(br) + data, err := io.ReadAll(br) if err != nil { t.Fatalf("Unexpected error when reading remaining data: %v", err) } @@ -2987,7 +2984,7 @@ func TestServerMaxRequestsPerConn(t *testing.T) { } verifyResponseHeader(t, &resp.Header, 200, 0, string(defaultContentType), "") - data, err := ioutil.ReadAll(br) + data, err := io.ReadAll(br) if err != nil { t.Fatalf("Unexpected error when reading remaining data: %v", err) } @@ -3023,7 +3020,7 @@ func TestServerConnectionClose(t *testing.T) { t.Fatal("expecting Connection: close header") } - data, err := ioutil.ReadAll(br) + data, err := io.ReadAll(br) if err != nil { t.Fatalf("Unexpected error when reading remaining data: %v", err) } @@ -3686,7 +3683,7 @@ func TestStreamRequestBody(t *testing.T) { pipe := fasthttputil.NewPipeConns() cc, sc := pipe.Conn1(), pipe.Conn2() - //write headers and part1 body + // write headers and part1 body if _, err := cc.Write([]byte(fmt.Sprintf("POST /foo2 HTTP/1.1\r\nHost: aaa.com\r\nContent-Length: %d\r\nContent-Type: aa\r\n\r\n", contentLength))); err != nil { t.Fatal(err) } @@ -3743,7 +3740,7 @@ func TestStreamRequestBodyExceedMaxSize(t *testing.T) { pipe := fasthttputil.NewPipeConns() cc, sc := pipe.Conn1(), pipe.Conn2() - //write headers and part1 body + // write headers and part1 body if _, err := cc.Write([]byte(fmt.Sprintf("POST /foo2 HTTP/1.1\r\nHost: aaa.com\r\nContent-Length: %d\r\nContent-Type: aa\r\n\r\n%s", contentLength, part1))); err != nil { t.Error(err) } @@ -3845,12 +3842,12 @@ func TestMaxReadTimeoutPerRequest(t *testing.T) { pipe := fasthttputil.NewPipeConns() cc, sc := pipe.Conn1(), pipe.Conn2() go func() { - //write headers + // write headers _, err := cc.Write(headers) if err != nil { t.Error(err) } - //write body + // write body for i := 0; i < 5*1024; i++ { time.Sleep(time.Millisecond) cc.Write([]byte{'a'}) //nolint:errcheck @@ -3899,7 +3896,7 @@ func TestMaxWriteTimeoutPerRequest(t *testing.T) { var resp Response go func() { - //write headers + // write headers _, err := cc.Write(headers) if err != nil { t.Error(err) diff --git a/server_timing_test.go b/server_timing_test.go index 0f2d4a7dbb..8e1150d676 100644 --- a/server_timing_test.go +++ b/server_timing_test.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "net" "net/http" "runtime" @@ -393,7 +392,7 @@ func benchmarkNetHTTPServerPost(b *testing.B, clientsCount, requestsPerConn int) if req.Method != MethodPost { b.Fatalf("Unexpected request method: %q", req.Method) } - body, err := ioutil.ReadAll(req.Body) + body, err := io.ReadAll(req.Body) if err != nil { b.Fatalf("Unexpected error: %v", err) } diff --git a/stackless/writer_test.go b/stackless/writer_test.go index 7f57bbdef6..fdbe16b04f 100644 --- a/stackless/writer_test.go +++ b/stackless/writer_test.go @@ -6,7 +6,6 @@ import ( "compress/gzip" "fmt" "io" - "io/ioutil" "testing" "time" ) @@ -96,7 +95,7 @@ func testWriterReuse(w Writer, r io.Reader, newReader func(io.Reader) io.Reader) w.Close() zr := newReader(r) - data, err := ioutil.ReadAll(zr) + data, err := io.ReadAll(zr) if err != nil { return fmt.Errorf("unexpected error: %w, data=%q", err, data) } diff --git a/stream_test.go b/stream_test.go index 2631e3d056..f4dcb5a62d 100644 --- a/stream_test.go +++ b/stream_test.go @@ -4,7 +4,6 @@ import ( "bufio" "fmt" "io" - "io/ioutil" "testing" "time" ) @@ -19,7 +18,7 @@ func TestNewStreamReader(t *testing.T) { close(ch) }) - data, err := ioutil.ReadAll(r) + data, err := io.ReadAll(r) if err != nil { t.Fatalf("unexpected error: %v", err) } @@ -88,7 +87,7 @@ func TestStreamReaderClose(t *testing.T) { // read trailing data go func() { - if _, err := ioutil.ReadAll(r); err != nil { + if _, err := io.ReadAll(r); err != nil { ch <- fmt.Errorf("unexpected error when reading trailing data: %w", err) return } diff --git a/streaming_test.go b/streaming_test.go index 1c7c25a842..084710b4da 100644 --- a/streaming_test.go +++ b/streaming_test.go @@ -4,7 +4,7 @@ import ( "bufio" "bytes" "fmt" - "io/ioutil" + "io" "sync" "testing" "time" @@ -36,7 +36,7 @@ aaaaaaaaaa` if string(ctx.Path()) == "/one" { body = string(ctx.PostBody()) } else { - all, err := ioutil.ReadAll(ctx.RequestBodyStream()) + all, err := io.ReadAll(ctx.RequestBodyStream()) if err != nil { t.Error(err) } @@ -106,9 +106,9 @@ func getChunkedTestEnv(t testing.TB) (*fasthttputil.InmemoryListener, []byte) { chunkedBody := createChunkedBody(body, nil, true) testHandler := func(ctx *RequestCtx) { - bodyBytes, err := ioutil.ReadAll(ctx.RequestBodyStream()) + bodyBytes, err := io.ReadAll(ctx.RequestBodyStream()) if err != nil { - t.Logf("ioutil read returned err=%v", err) + t.Logf("io read returned err=%v", err) t.Error("unexpected error while reading request body stream") } @@ -164,7 +164,7 @@ Trailer: Foo, Bar s := &Server{ StreamRequestBody: true, Handler: func(ctx *RequestCtx) { - all, err := ioutil.ReadAll(ctx.RequestBodyStream()) + all, err := io.ReadAll(ctx.RequestBodyStream()) if err != nil { t.Errorf("unexpected error: %v", err) } diff --git a/workerpool_test.go b/workerpool_test.go index b8267ab8f0..c7c8ed9e16 100644 --- a/workerpool_test.go +++ b/workerpool_test.go @@ -1,7 +1,7 @@ package fasthttp import ( - "io/ioutil" + "io" "net" "testing" "time" @@ -118,7 +118,7 @@ func testWorkerPoolMaxWorkersCount(t *testing.T) { if _, err = conn.Write([]byte("foobar")); err != nil { t.Errorf("unexpected error: %v", err) } - data, err := ioutil.ReadAll(conn) + data, err := io.ReadAll(conn) if err != nil { t.Errorf("unexpected error: %v", err) }