import (
"bytes"
"io"
- "io/ioutil"
"strconv"
"strings"
"time"
continue // This is a meta header affecting the next header
case TypeGNULongName, TypeGNULongLink:
format.mayOnlyBe(FormatGNU)
- realname, err := ioutil.ReadAll(tr)
+ realname, err := io.ReadAll(tr)
if err != nil {
return nil, err
}
// parsePAX parses PAX headers.
// If an extended header (type 'x') is invalid, ErrHeader is returned
func parsePAX(r io.Reader) (map[string]string, error) {
- buf, err := ioutil.ReadAll(r)
+ buf, err := io.ReadAll(r)
if err != nil {
return nil, err
}
}
}
- copySkipped, err := io.CopyN(ioutil.Discard, r, n-seekSkipped)
+ copySkipped, err := io.CopyN(io.Discard, r, n-seekSkipped)
if err == io.EOF && seekSkipped+copySkipped < n {
err = io.ErrUnexpectedEOF
}
}
cnt++
if s2 == "manual" {
- if _, err = tr.writeTo(ioutil.Discard); err != nil {
+ if _, err = tr.writeTo(io.Discard); err != nil {
break
}
}
if !reflect.DeepEqual(rHdr, hdr) {
t.Errorf("Header mismatch.\n got %+v\nwant %+v", rHdr, hdr)
}
- rData, err := ioutil.ReadAll(tr)
+ rData, err := io.ReadAll(tr)
if err != nil {
t.Fatalf("Read: %v", err)
}
b.Run(v.label, func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
- // Writing to ioutil.Discard because we want to
+ // Writing to io.Discard because we want to
// test purely the writer code and not bring in disk performance into this.
- tw := NewWriter(ioutil.Discard)
+ tw := NewWriter(io.Discard)
for _, file := range v.files {
if err := tw.WriteHeader(file.hdr); err != nil {
b.Errorf("unexpected WriteHeader error: %v", err)
if _, err := tr.Next(); err != nil {
b.Errorf("unexpected Next error: %v", err)
}
- if _, err := io.Copy(ioutil.Discard, tr); err != nil {
+ if _, err := io.Copy(io.Discard, tr); err != nil {
b.Errorf("unexpected Copy error : %v", err)
}
}
if err != nil {
panic(err)
}
- b, err = ioutil.ReadAll(f)
+ b, err = io.ReadAll(f)
if err != nil {
panic(err)
}
continue
}
if f.UncompressedSize64 < 1e6 {
- n, err := io.Copy(ioutil.Discard, r)
+ n, err := io.Copy(io.Discard, r)
if i == 3 && err != io.ErrUnexpectedEOF {
t.Errorf("File[3] error = %v; want io.ErrUnexpectedEOF", err)
}
if err != nil {
t.Fatal(err)
}
- _, err = ioutil.ReadAll(r)
+ _, err = io.ReadAll(r)
if err != io.ErrUnexpectedEOF {
t.Errorf("File[0] error = %v; want io.ErrUnexpectedEOF", err)
}
"compress/flate"
"errors"
"io"
- "io/ioutil"
"sync"
)
compressors.Store(Store, Compressor(func(w io.Writer) (io.WriteCloser, error) { return &nopCloser{w}, nil }))
compressors.Store(Deflate, Compressor(func(w io.Writer) (io.WriteCloser, error) { return newFlateWriter(w), nil }))
- decompressors.Store(Store, Decompressor(ioutil.NopCloser))
+ decompressors.Store(Store, Decompressor(io.NopCloser))
decompressors.Store(Deflate, Decompressor(newFlateReader))
}
}
func TestWriterDir(t *testing.T) {
- w := NewWriter(ioutil.Discard)
+ w := NewWriter(io.Discard)
dw, err := w.Create("dir/")
if err != nil {
t.Fatal(err)
if err != nil {
t.Fatal("opening:", err)
}
- b, err := ioutil.ReadAll(rc)
+ b, err := io.ReadAll(rc)
if err != nil {
t.Fatal("reading:", err)
}
"hash"
"internal/testenv"
"io"
- "io/ioutil"
"runtime"
"sort"
"strings"
t.Fatal("read:", err)
}
}
- gotEnd, err := ioutil.ReadAll(rc)
+ gotEnd, err := io.ReadAll(rc)
if err != nil {
t.Fatal("read end:", err)
}
"errors"
"fmt"
"io"
- "io/ioutil"
"strings"
"testing"
"testing/iotest"
func TestLinesAfterRead(t *testing.T) {
l := NewReaderSize(bytes.NewReader([]byte("foo")), minReadBufferSize)
- _, err := ioutil.ReadAll(l)
+ _, err := io.ReadAll(l)
if err != nil {
t.Error(err)
return
}
}
-// A writeCountingDiscard is like ioutil.Discard and counts the number of times
+// A writeCountingDiscard is like io.Discard and counts the number of times
// Write is called on it.
type writeCountingDiscard int
t.Errorf("buf = %q; want foo", buf)
}
r.Reset(strings.NewReader("bar bar"))
- all, err := ioutil.ReadAll(r)
+ all, err := io.ReadAll(r)
if err != nil {
t.Fatal(err)
}
buf := make([]byte, bufSize)
r := bytes.NewReader(buf)
srcReader := NewReaderSize(onlyReader{r}, 1<<10)
- if _, ok := ioutil.Discard.(io.ReaderFrom); !ok {
- b.Fatal("ioutil.Discard doesn't support ReaderFrom")
+ if _, ok := io.Discard.(io.ReaderFrom); !ok {
+ b.Fatal("io.Discard doesn't support ReaderFrom")
}
for i := 0; i < b.N; i++ {
r.Seek(0, io.SeekStart)
srcReader.Reset(onlyReader{r})
- n, err := srcReader.WriteTo(ioutil.Discard)
+ n, err := srcReader.WriteTo(io.Discard)
if err != nil {
b.Fatal(err)
}
str := strings.Repeat("x", 16<<10)
for i := 0; i < b.N; i++ {
br := NewReader(strings.NewReader(str))
- n, err := io.Copy(ioutil.Discard, br)
+ n, err := io.Copy(io.Discard, br)
if err != nil {
b.Fatal(err)
}
str := strings.Repeat("x", 1<<10)
bs := []byte(str)
for i := 0; i < b.N; i++ {
- bw := NewWriter(ioutil.Discard)
+ bw := NewWriter(io.Discard)
bw.Flush()
bw.WriteByte('a')
bw.Flush()
func BenchmarkWriterFlush(b *testing.B) {
b.ReportAllocs()
- bw := NewWriter(ioutil.Discard)
+ bw := NewWriter(io.Discard)
str := strings.Repeat("x", 50)
for i := 0; i < b.N; i++ {
bw.WriteString(str)
. "bytes"
"fmt"
"io"
- "io/ioutil"
"sync"
"testing"
)
type justWriter struct {
io.Writer
}
- discard := justWriter{ioutil.Discard} // hide ReadFrom
+ discard := justWriter{io.Discard} // hide ReadFrom
var with, withOut nErr
with.n, with.err = io.Copy(discard, NewReader(nil))
// tests that Len is affected by reads, but Size is not.
func TestReaderLenSize(t *testing.T) {
r := NewReader([]byte("abc"))
- io.CopyN(ioutil.Discard, r, 1)
+ io.CopyN(io.Discard, r, 1)
if r.Len() != 2 {
t.Errorf("Len = %d; want 2", r.Len())
}
if err := r.UnreadRune(); err == nil {
t.Errorf("UnreadRune: expected error, got nil")
}
- buf, err := ioutil.ReadAll(r)
+ buf, err := io.ReadAll(r)
if err != nil {
t.Errorf("ReadAll: unexpected error: %v", err)
}
t.Errorf("UnreadRune: got nil, want error")
}
- if n, err := (&Reader{}).WriteTo(ioutil.Discard); n != 0 || err != nil {
+ if n, err := (&Reader{}).WriteTo(io.Discard); n != 0 || err != nil {
t.Errorf("WriteTo: got %d, %v; want 0, nil", n, err)
}
}
"go/parser"
"go/scanner"
"go/token"
+ "io"
"io/fs"
"io/ioutil"
"os"
defer f.Close()
}
- src, err := ioutil.ReadAll(f)
+ src, err := io.ReadAll(f)
if err != nil {
return err
}
import (
"context"
"fmt"
+ "io"
"io/ioutil"
"os"
"path/filepath"
f, err := lockedfile.Edit(filepath.Join(dir, "testexpire.txt"))
if err == nil {
now := time.Now().UnixNano()
- buf, _ := ioutil.ReadAll(f)
+ buf, _ := io.ReadAll(f)
prev, _ := strconv.ParseInt(strings.TrimSpace(string(buf)), 10, 64)
if now > prev {
if err = f.Truncate(0); err == nil {
"errors"
"fmt"
"internal/testenv"
+ "io"
"io/fs"
"io/ioutil"
"os"
t.Errorf("Open(%q): got error %v, want nil", tc.path, err)
continue
}
- contents, err := ioutil.ReadAll(f)
+ contents, err := io.ReadAll(f)
if err != nil {
t.Errorf("unexpected error reading contents of file: %v", err)
}
r.readString(imports)
}
-// ReadComments is like ioutil.ReadAll, except that it only reads the leading
+// ReadComments is like io.ReadAll, except that it only reads the leading
// block of comments in the file.
func ReadComments(f io.Reader) ([]byte, error) {
r := &importReader{b: bufio.NewReader(f)}
return r.buf, r.err
}
-// ReadImports is like ioutil.ReadAll, except that it expects a Go file as input
+// ReadImports is like io.ReadAll, except that it expects a Go file as input
// and stops reading the input once the imports have completed.
func ReadImports(f io.Reader, reportSyntaxError bool, imports *[]string) ([]byte, error) {
r := &importReader{b: bufio.NewReader(f)}
"fmt"
"io"
"io/fs"
- "io/ioutil"
"os"
"runtime"
)
}
defer f.Close()
- return ioutil.ReadAll(f)
+ return io.ReadAll(f)
}
// Write opens the named file (creating it with the given permissions if needed),
}
defer f.Close()
- old, err := ioutil.ReadAll(f)
+ old, err := io.ReadAll(f)
if err != nil {
return err
}
"fmt"
"io"
"io/fs"
- "io/ioutil"
"net/url"
"os"
"os/exec"
return nil, err
}
- return ioutil.NopCloser(bytes.NewReader(archive)), nil
+ return io.NopCloser(bytes.NewReader(archive)), nil
}
// ensureGitAttributes makes sure export-subst and export-ignore features are
}
}()
- b, err := ioutil.ReadAll(f)
+ b, err := io.ReadAll(f)
if err != nil {
return err
}
"flag"
"fmt"
"internal/testenv"
+ "io"
"io/fs"
"io/ioutil"
"log"
if tt.err != "" {
t.Fatalf("ReadZip: no error, wanted %v", tt.err)
}
- zipdata, err := ioutil.ReadAll(rc)
+ zipdata, err := io.ReadAll(rc)
if err != nil {
t.Fatal(err)
}
"bytes"
"flag"
"fmt"
+ "io"
"io/ioutil"
"log"
"os"
fmt.Fprintf(os.Stderr, "?%s\n", err)
continue
}
- data, err := ioutil.ReadAll(rc)
+ data, err := io.ReadAll(rc)
rc.Close()
if err != nil {
fmt.Fprintf(os.Stderr, "?%s\n", err)
func (f dataFile) Path() string { return f.name }
func (f dataFile) Lstat() (fs.FileInfo, error) { return dataFileInfo{f}, nil }
func (f dataFile) Open() (io.ReadCloser, error) {
- return ioutil.NopCloser(bytes.NewReader(f.data)), nil
+ return io.NopCloser(bytes.NewReader(f.data)), nil
}
type dataFileInfo struct {
// goModSum returns the checksum for the go.mod contents.
func goModSum(data []byte) (string, error) {
return dirhash.Hash1([]string{"go.mod"}, func(string) (io.ReadCloser, error) {
- return ioutil.NopCloser(bytes.NewReader(data)), nil
+ return io.NopCloser(bytes.NewReader(data)), nil
})
}
"fmt"
"io"
"io/fs"
- "io/ioutil"
"net/url"
"path"
pathpkg "path"
return nil, err
}
defer body.Close()
- return ioutil.ReadAll(body)
+ return io.ReadAll(body)
}
func (p *proxyRepo) getBody(path string) (io.ReadCloser, error) {
"bytes"
"errors"
"fmt"
+ "io"
"io/fs"
- "io/ioutil"
"net/url"
"os"
"path/filepath"
return err
}
defer f.Close()
- data, err := ioutil.ReadAll(f)
+ data, err := io.ReadAll(f)
if err != nil {
return err
}
"fmt"
"io"
"io/fs"
- "io/ioutil"
"net/url"
"strings"
"unicode"
if err := resp.Err(); err != nil {
return nil, err
}
- b, err := ioutil.ReadAll(resp.Body)
+ b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("reading %s: %v", u.Redacted(), err)
}
}
// Ensure that r.errorDetail has been populated.
- _, _ = io.Copy(ioutil.Discard, r.Body)
+ _, _ = io.Copy(io.Discard, r.Body)
s := r.errorDetail.buf.String()
if !utf8.ValidString(s) {
}
h1, err := dirhash.Hash1(names, func(name string) (io.ReadCloser, error) {
data := files[name]
- return ioutil.NopCloser(bytes.NewReader(data)), nil
+ return io.NopCloser(bytes.NewReader(data)), nil
})
if err != nil {
return nil, err
}
h1mod, err := dirhash.Hash1([]string{"go.mod"}, func(string) (io.ReadCloser, error) {
- return ioutil.NopCloser(bytes.NewReader(gomod)), nil
+ return io.NopCloser(bytes.NewReader(gomod)), nil
})
if err != nil {
return nil, err
if err != nil {
t.Fatal(err)
}
- data, err := ioutil.ReadAll(f)
+ data, err := io.ReadAll(f)
f.Close()
if err != nil {
t.Fatal(err)
perm = fi.Mode().Perm()
}
- src, err := ioutil.ReadAll(in)
+ src, err := io.ReadAll(in)
if err != nil {
return err
}
"crypto/tls"
"debug/dwarf"
"fmt"
- "io/ioutil"
+ "io"
"net/http"
"net/url"
"os"
func statusCodeError(resp *http.Response) error {
if resp.Header.Get("X-Go-Pprof") != "" && strings.Contains(resp.Header.Get("Content-Type"), "text/plain") {
// error is from pprof endpoint
- if body, err := ioutil.ReadAll(resp.Body); err == nil {
+ if body, err := io.ReadAll(resp.Body); err == nil {
return fmt.Errorf("server response: %s - %s", resp.Status, body)
}
}
"cmd/internal/traceviewer"
"context"
"internal/trace"
- "io/ioutil"
+ "io"
rtrace "runtime/trace"
"strings"
"sync"
// Use the default viewerDataTraceConsumer but replace
// consumeViewerEvent to intercept the ViewerEvents for testing.
- c := viewerDataTraceConsumer(ioutil.Discard, 0, 1<<63-1)
+ c := viewerDataTraceConsumer(io.Discard, 0, 1<<63-1)
c.consumeViewerEvent = func(ev *traceviewer.Event, _ bool) {
if ev.Name == "Goroutines" {
cnt := ev.Arg.(*goroutineCountersArg)
gs: map[uint64]bool{10: true},
}
- c := viewerDataTraceConsumer(ioutil.Discard, 0, 1<<63-1)
+ c := viewerDataTraceConsumer(io.Discard, 0, 1<<63-1)
if err := generateTrace(params, c); err != nil {
t.Fatalf("generateTrace failed: %v", err)
}
endTime: int64(1<<63 - 1),
}
- c := viewerDataTraceConsumer(ioutil.Discard, 0, 1<<63-1)
+ c := viewerDataTraceConsumer(io.Discard, 0, 1<<63-1)
marks := 0
c.consumeViewerEvent = func(ev *traceviewer.Event, _ bool) {
tasks: []*taskDesc{task},
}
- c := viewerDataTraceConsumer(ioutil.Discard, 0, 1<<63-1)
+ c := viewerDataTraceConsumer(io.Discard, 0, 1<<63-1)
var logBeforeTaskEnd, logAfterTaskEnd bool
c.consumeViewerEvent = func(ev *traceviewer.Event, _ bool) {
"bytes"
"cmd/internal/traceviewer"
traceparser "internal/trace"
- "io/ioutil"
+ "io"
"runtime"
"runtime/trace"
"sync"
// Check only one thread for the pipe read goroutine is
// considered in-syscall.
- c := viewerDataTraceConsumer(ioutil.Discard, 0, 1<<63-1)
+ c := viewerDataTraceConsumer(io.Discard, 0, 1<<63-1)
c.consumeViewerEvent = func(ev *traceviewer.Event, _ bool) {
if ev.Name == "Threads" {
arg := ev.Arg.(*threadCountersArg)
for i, v := range vectors {
rd := NewReader(bytes.NewReader(v.input))
- buf, err := ioutil.ReadAll(rd)
+ buf, err := io.ReadAll(rd)
if fail := bool(err != nil); fail != v.fail {
if fail {
func benchmarkDecode(b *testing.B, compressed []byte) {
// Determine the uncompressed size of testfile.
- uncompressedSize, err := io.Copy(ioutil.Discard, NewReader(bytes.NewReader(compressed)))
+ uncompressedSize, err := io.Copy(io.Discard, NewReader(bytes.NewReader(compressed)))
if err != nil {
b.Fatal(err)
}
for i := 0; i < b.N; i++ {
r := bytes.NewReader(compressed)
- io.Copy(ioutil.Discard, NewReader(r))
+ io.Copy(io.Discard, NewReader(r))
}
}
if testing.Short() {
t.Skip("skipping sparse chunk during short test")
}
- w, err := NewWriter(ioutil.Discard, 1)
+ w, err := NewWriter(io.Discard, 1)
if err != nil {
t.Errorf("NewWriter: %v", err)
return
// stream should work for ordinary reader too
r = NewReader(buf1)
- out, err = ioutil.ReadAll(r)
+ out, err = io.ReadAll(r)
if err != nil {
t.Errorf("testSync: read: %s", err)
return
t.Logf("level: %d, size:%.2f%%, %d b\n", level, float64(buffer.Len()*100)/float64(limit), buffer.Len())
}
r := NewReader(&buffer)
- out, err := ioutil.ReadAll(r)
+ out, err := io.ReadAll(r)
if err != nil {
t.Errorf("read: %s", err)
return
w.Close()
r := NewReaderDict(&b, []byte(dict))
- data, err := ioutil.ReadAll(r)
+ data, err := io.ReadAll(r)
if err != nil {
t.Fatal(err)
}
t.Logf("test disabled with -short")
return
}
- w, err := NewWriter(ioutil.Discard, 1)
+ w, err := NewWriter(io.Discard, 1)
if err != nil {
t.Fatalf("NewWriter: %v", err)
}
if testing.Short() && level > 1 {
break
}
- w, err := NewWriter(ioutil.Discard, level)
+ w, err := NewWriter(io.Discard, level)
if err != nil {
t.Fatalf("NewWriter: %v", err)
}
for i := 0; i < n; i++ {
w.Write(buf)
}
- w.Reset(ioutil.Discard)
+ w.Reset(io.Discard)
- wref, err := NewWriter(ioutil.Discard, level)
+ wref, err := NewWriter(io.Discard, level)
if err != nil {
t.Fatalf("NewWriter: %v", err)
}
}
r := NewReader(buf)
- got, err := ioutil.ReadAll(r)
+ got, err := io.ReadAll(r)
if err != nil {
t.Errorf("i=%d, firstN=%d, flush=%t: ReadAll: %v", i, firstN, flush, err)
continue
}
r := NewReader(buf)
- dst, err := ioutil.ReadAll(r)
+ dst, err := io.ReadAll(r)
r.Close()
if err != nil {
report("ReadAll: ", err)
wg.Add(1)
go func(level int) {
defer wg.Done()
- zw, err := NewWriter(ioutil.Discard, level)
+ zw, err := NewWriter(io.Discard, level)
if err != nil {
t.Errorf("level %d, NewWriter() = %v, want nil", level, err)
}
if err := zw.Close(); err != nil {
t.Errorf("level %d, Close() = %v, want nil", level, err)
}
- zw.Reset(ioutil.Discard)
+ zw.Reset(io.Discard)
}(level)
}
}
"bytes"
"encoding/hex"
"io"
- "io/ioutil"
"strings"
"testing"
)
if err != nil {
t.Fatal(err)
}
- data, err = ioutil.ReadAll(NewReader(bytes.NewReader(data)))
+ data, err = io.ReadAll(NewReader(bytes.NewReader(data)))
if tc.want == "fail" {
if err == nil {
t.Errorf("#%d (%s): got nil error, want non-nil", i, tc.desc)
for i := 0; i < len(data)-1; i++ {
r := NewReader(strings.NewReader(data[:i]))
- _, err := io.Copy(ioutil.Discard, r)
+ _, err := io.Copy(io.Discard, r)
if err != io.ErrUnexpectedEOF {
t.Errorf("io.Copy(%d) on truncated stream: got %v, want %v", i, err, io.ErrUnexpectedEOF)
}
import (
"bytes"
"io"
- "io/ioutil"
"strings"
"testing"
)
for i, v := range vectors {
r := strings.NewReader(v.input)
zr := NewReader(r)
- b, err := ioutil.ReadAll(zr)
+ b, err := io.ReadAll(zr)
if err != io.ErrUnexpectedEOF {
t.Errorf("test %d, error mismatch: got %v, want io.ErrUnexpectedEOF", i, err)
}
func TestNlitOutOfRange(t *testing.T) {
// Trying to decode this bogus flate data, which has a Huffman table
// with nlit=288, should not panic.
- io.Copy(ioutil.Discard, NewReader(strings.NewReader(
+ io.Copy(io.Discard, NewReader(strings.NewReader(
"\xfc\xfe\x36\xe7\x5e\x1c\xef\xb3\x55\x58\x77\xb6\x56\xb5\x43\xf4"+
"\x6f\xf2\xd2\xe6\x3d\x99\xa0\x85\x8c\x48\xeb\xf8\xda\x83\x04\x2a"+
"\x75\xc4\xf8\x0f\x12\x11\xb9\xb4\x4b\x09\xa0\xbe\x8b\x91\x4c")))
runtime.GC()
b.StartTimer()
for i := 0; i < b.N; i++ {
- io.Copy(ioutil.Discard, NewReader(bytes.NewReader(buf1)))
+ io.Copy(io.Discard, NewReader(bytes.NewReader(buf1)))
}
})
}
"bytes"
"fmt"
"io"
- "io/ioutil"
"math/rand"
"runtime"
"testing"
copy(buf1[i:], buf0)
}
buf0 = nil
- w, err := NewWriter(ioutil.Discard, level)
+ w, err := NewWriter(io.Discard, level)
if err != nil {
b.Fatal(err)
}
runtime.GC()
b.StartTimer()
for i := 0; i < b.N; i++ {
- w.Reset(ioutil.Discard)
+ w.Reset(io.Discard)
w.Write(buf1)
w.Close()
}
t.Fatal("Level", l, "Expected an error on close")
}
- w.Reset(ioutil.Discard)
+ w.Reset(io.Discard)
n2, err = w.Write([]byte{1, 2, 3, 4, 5, 6})
if err != nil {
t.Fatal("Level", l, "Got unexpected error after reset:", err)
w.Close()
for ; offset <= 256; offset *= 2 {
- w, err := NewWriter(ioutil.Discard, level)
+ w, err := NewWriter(io.Discard, level)
if err != nil {
t.Fatalf("NewWriter: level %d: %v", level, err)
}
"compress/flate"
"encoding/base64"
"io"
- "io/ioutil"
"os"
"strings"
"testing"
defer gzip.Close()
done := make(chan bool, 1)
go func() {
- _, err := io.Copy(ioutil.Discard, gzip)
+ _, err := io.Copy(io.Discard, gzip)
if err == nil {
t.Errorf("Copy succeeded")
} else {
const hello = "hello world\n"
r.Multistream(false)
- data, err := ioutil.ReadAll(&r)
+ data, err := io.ReadAll(&r)
if string(data) != hello || err != nil {
t.Fatalf("first stream = %q, %v, want %q, %v", string(data), err, hello, nil)
}
t.Fatalf("second reset: %v", err)
}
r.Multistream(false)
- data, err = ioutil.ReadAll(&r)
+ data, err = io.ReadAll(&r)
if string(data) != hello || err != nil {
t.Fatalf("second stream = %q, %v, want %q, %v", string(data), err, hello, nil)
}
}
continue
}
- _, err = io.Copy(ioutil.Discard, r)
+ _, err = io.Copy(io.Discard, r)
if ferr, ok := err.(*flate.ReadError); ok {
err = ferr.Err
}
"bufio"
"bytes"
"io"
- "io/ioutil"
"reflect"
"testing"
"time"
if want := (Header{OS: 255}); !reflect.DeepEqual(r.Header, want) {
t.Errorf("Header mismatch:\ngot %#v\nwant %#v", r.Header, want)
}
- b, err := ioutil.ReadAll(r)
+ b, err := io.ReadAll(r)
if err != nil {
t.Fatalf("ReadAll: %v", err)
}
if err != nil {
t.Fatalf("NewReader: %v", err)
}
- b, err := ioutil.ReadAll(r)
+ b, err := io.ReadAll(r)
if err != nil {
t.Fatalf("ReadAll: %v", err)
}
t.Errorf("NewReader: %v", err)
continue
}
- _, err = ioutil.ReadAll(r)
+ _, err = io.ReadAll(r)
if err != nil {
t.Errorf("ReadAll: %v", err)
continue
if err != nil {
t.Fatal(err)
}
- data, err := ioutil.ReadAll(r)
+ data, err := io.ReadAll(r)
if string(data) != "hello world\n" || err != nil {
t.Fatalf("ReadAll = %q, %v, want %q, nil", data, err, "hello world")
}
in = append(in, 0x80, 0xff, 0x0f, 0x08)
r := NewReader(bytes.NewReader(in), LSB, 8)
- nDecoded, err := io.Copy(ioutil.Discard, r)
+ nDecoded, err := io.Copy(io.Discard, r)
if err != nil {
t.Fatalf("Copy: %v", err)
}
runtime.GC()
b.StartTimer()
for i := 0; i < b.N; i++ {
- io.Copy(ioutil.Discard, NewReader(bytes.NewReader(buf1), LSB, 8))
+ io.Copy(io.Discard, NewReader(bytes.NewReader(buf1), LSB, 8))
}
})
}
defer lzwr.Close()
// Compare the two.
- b0, err0 := ioutil.ReadAll(golden)
- b1, err1 := ioutil.ReadAll(lzwr)
+ b0, err0 := io.ReadAll(golden)
+ b1, err1 := io.ReadAll(lzwr)
if err0 != nil {
t.Errorf("%s (order=%d litWidth=%d): %v", fn, order, litWidth, err0)
return
}
func TestWriterReturnValues(t *testing.T) {
- w := NewWriter(ioutil.Discard, LSB, 8)
+ w := NewWriter(io.Discard, LSB, 8)
n, err := w.Write([]byte("asdf"))
if n != 4 || err != nil {
t.Errorf("got %d, %v, want 4, nil", n, err)
}
func TestSmallLitWidth(t *testing.T) {
- w := NewWriter(ioutil.Discard, LSB, 2)
+ w := NewWriter(io.Discard, LSB, 2)
if _, err := w.Write([]byte{0x03}); err != nil {
t.Fatalf("write a byte < 1<<2: %v", err)
}
b.Run(fmt.Sprint("1e", e), func(b *testing.B) {
b.SetBytes(int64(n))
for i := 0; i < b.N; i++ {
- w := NewWriter(ioutil.Discard, LSB, 8)
+ w := NewWriter(io.Discard, LSB, 8)
w.Write(buf1)
w.Close()
}
return
}
defer golden.Close()
- b0, err0 := ioutil.ReadAll(golden)
+ b0, err0 := io.ReadAll(golden)
if err0 != nil {
t.Errorf("%s (level=%d, dict=%q): %v", fn, level, d, err0)
return
defer zlibr.Close()
// Compare the decompressed data.
- b1, err1 := ioutil.ReadAll(zlibr)
+ b1, err1 := io.ReadAll(zlibr)
if err1 != nil {
t.Errorf("%s (level=%d, dict=%q): %v", fn, level, d, err1)
return
}
defer cli.Close()
clientState = cli.ConnectionState()
- buf, err := ioutil.ReadAll(cli)
+ buf, err := io.ReadAll(cli)
if err != nil {
t.Errorf("failed to call cli.Read: %v", err)
}
"fmt"
"internal/testenv"
"io"
- "io/ioutil"
"math"
"net"
"os"
}
defer srv.Close()
- data, err := ioutil.ReadAll(srv)
+ data, err := io.ReadAll(srv)
if err != nil {
return err
}
return fmt.Errorf("CloseWrite error = %v; want errShutdown", err)
}
- data, err := ioutil.ReadAll(conn)
+ data, err := io.ReadAll(conn)
if err != nil {
return err
}
}
defer srv.Close()
- _, err = ioutil.ReadAll(srv)
+ _, err = io.ReadAll(srv)
if err == nil {
return errors.New("unexpected lack of error from server")
}
continue
}
- der, err := ioutil.ReadAll(tr)
+ der, err := io.ReadAll(tr)
if err != nil {
log.Fatal(err)
}
"compress/gzip"
"debug/elf"
"internal/testenv"
+ "io"
"io/ioutil"
"os"
"os/exec"
t.Fatal(err)
}
var dat []byte
- dat, err = ioutil.ReadAll(gzReader)
+ dat, err = io.ReadAll(gzReader)
if err != nil {
t.Fatal(err)
}
import (
"bytes"
"io"
- "io/ioutil"
"strings"
"testing"
)
func TestDecoder(t *testing.T) {
for _, p := range pairs {
decoder := NewDecoder(strings.NewReader(p.encoded))
- dbuf, err := ioutil.ReadAll(decoder)
+ dbuf, err := io.ReadAll(decoder)
if err != nil {
t.Fatal("Read failed", err)
}
if err != nil {
t.Fatalf("Encoder.Close() = %v want nil", err)
}
- decoded, err := ioutil.ReadAll(NewDecoder(encoded))
+ decoded, err := io.ReadAll(NewDecoder(encoded))
if err != nil {
t.Fatalf("io.ReadAll(NewDecoder(...)): %v", err)
}
func TestDecoderInternalWhitespace(t *testing.T) {
s := strings.Repeat(" ", 2048) + "z"
- decoded, err := ioutil.ReadAll(NewDecoder(strings.NewReader(s)))
+ decoded, err := io.ReadAll(NewDecoder(strings.NewReader(s)))
if err != nil {
t.Errorf("Decode gave error %v", err)
}
"bytes"
"errors"
"io"
- "io/ioutil"
"strings"
"testing"
)
if err != nil {
t.Fatalf("Encoder.Close() = %v want nil", err)
}
- decoded, err := ioutil.ReadAll(NewDecoder(StdEncoding, encoded))
+ decoded, err := io.ReadAll(NewDecoder(StdEncoding, encoded))
if err != nil {
- t.Fatalf("ioutil.ReadAll(NewDecoder(...)): %v", err)
+ t.Fatalf("io.ReadAll(NewDecoder(...)): %v", err)
}
if !bytes.Equal(raw, decoded) {
encodedShort := strings.ReplaceAll(encoded, "\n", "")
dec := NewDecoder(StdEncoding, strings.NewReader(encoded))
- res1, err := ioutil.ReadAll(dec)
+ res1, err := io.ReadAll(dec)
if err != nil {
t.Errorf("ReadAll failed: %v", err)
}
dec = NewDecoder(StdEncoding, strings.NewReader(encodedShort))
var res2 []byte
- res2, err = ioutil.ReadAll(dec)
+ res2, err = io.ReadAll(dec)
if err != nil {
t.Errorf("ReadAll failed: %v", err)
}
}()
decoder := NewDecoder(StdEncoding, pr)
- _, err := ioutil.ReadAll(decoder)
+ _, err := io.ReadAll(decoder)
if err != testcase.expected {
t.Errorf("Expected %v, got %v; case %s %+v", testcase.expected, err, testcase.prefix, chunks)
encoded = strings.ReplaceAll(encoded, "=", "")
}
- decReader, err := ioutil.ReadAll(NewDecoder(encoding, strings.NewReader(encoded)))
+ decReader, err := io.ReadAll(NewDecoder(encoding, strings.NewReader(encoded)))
if err != nil {
t.Errorf("NewDecoder error: %v", err)
}
"errors"
"fmt"
"io"
- "io/ioutil"
"reflect"
"runtime/debug"
"strings"
if err != nil {
t.Fatalf("Encoder.Close() = %v want nil", err)
}
- decoded, err := ioutil.ReadAll(NewDecoder(StdEncoding, encoded))
+ decoded, err := io.ReadAll(NewDecoder(StdEncoding, encoded))
if err != nil {
- t.Fatalf("ioutil.ReadAll(NewDecoder(...)): %v", err)
+ t.Fatalf("io.ReadAll(NewDecoder(...)): %v", err)
}
if !bytes.Equal(raw, decoded) {
})
errc := make(chan error, 1)
go func() {
- _, err := ioutil.ReadAll(d)
+ _, err := io.ReadAll(d)
errc <- err
}()
select {
encodedShort := strings.ReplaceAll(encoded, "\n", "")
dec := NewDecoder(StdEncoding, strings.NewReader(encoded))
- res1, err := ioutil.ReadAll(dec)
+ res1, err := io.ReadAll(dec)
if err != nil {
t.Errorf("ReadAll failed: %v", err)
}
dec = NewDecoder(StdEncoding, strings.NewReader(encodedShort))
var res2 []byte
- res2, err = ioutil.ReadAll(dec)
+ res2, err = io.ReadAll(dec)
if err != nil {
t.Errorf("ReadAll failed: %v", err)
}
// Through reader. Used to fail.
r := NewDecoder(RawURLEncoding, bytes.NewReader([]byte(source)))
- dec2, err := ioutil.ReadAll(io.LimitReader(r, 100))
+ dec2, err := io.ReadAll(io.LimitReader(r, 100))
if err != nil || !bytes.Equal(dec2, want) {
t.Errorf("reading NewDecoder(RawURLEncoding, %q) = %x, %v, want %x, nil", source, dec2, err, want)
}
// Should work with padding.
r = NewDecoder(URLEncoding, bytes.NewReader([]byte(source+"==")))
- dec3, err := ioutil.ReadAll(r)
+ dec3, err := io.ReadAll(r)
if err != nil || !bytes.Equal(dec3, want) {
t.Errorf("reading NewDecoder(URLEncoding, %q) = %x, %v, want %x, nil", source+"==", dec3, err, want)
}
"bytes"
"fmt"
"io"
- "io/ioutil"
"math"
"reflect"
"strings"
b.SetBytes(int64(Size(&s)))
b.ResetTimer()
for i := 0; i < b.N; i++ {
- Write(ioutil.Discard, BigEndian, &s)
+ Write(io.Discard, BigEndian, &s)
}
}
"bytes"
"encoding/hex"
"fmt"
- "io/ioutil"
+ "io"
"reflect"
"strings"
"testing"
}
}()
- encodeErr = NewEncoder(ioutil.Discard).Encode(value)
+ encodeErr = NewEncoder(io.Discard).Encode(value)
return
}
"bytes"
"fmt"
"io"
- "io/ioutil"
"strings"
"testing"
)
func TestDecoderErr(t *testing.T) {
for _, tt := range errTests {
dec := NewDecoder(strings.NewReader(tt.in))
- out, err := ioutil.ReadAll(dec)
+ out, err := io.ReadAll(dec)
wantErr := tt.err
// Decoder is reading from stream, so it reports io.ErrUnexpectedEOF instead of ErrLength.
if wantErr == ErrLength {
"compress/gzip"
"fmt"
"internal/testenv"
- "io/ioutil"
+ "io"
"os"
"reflect"
"runtime"
if err != nil {
panic(err)
}
- data, err := ioutil.ReadAll(gz)
+ data, err := io.ReadAll(gz)
if err != nil {
panic(err)
}
b.StartTimer()
}
b.RunParallel(func(pb *testing.PB) {
- enc := NewEncoder(ioutil.Discard)
+ enc := NewEncoder(io.Discard)
for pb.Next() {
if err := enc.Encode(&codeStruct); err != nil {
b.Fatal("Encode:", err)
}{}
b.RunParallel(func(pb *testing.PB) {
- enc := NewEncoder(ioutil.Discard)
+ enc := NewEncoder(io.Discard)
for pb.Next() {
if err := enc.Encode(&m); err != nil {
import (
"bytes"
"io"
- "io/ioutil"
"log"
"net"
"net/http"
if m.Name != "Gopher" {
t.Errorf("Name = %q; want Gopher", m.Name)
}
- rest, err := ioutil.ReadAll(d.Buffered())
+ rest, err := io.ReadAll(d.Buffered())
if err != nil {
t.Fatal(err)
}
v := &T{"foo", "bar"}
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- if err := NewEncoder(ioutil.Discard).Encode(v); err != nil {
+ if err := NewEncoder(io.Discard).Encode(v); err != nil {
b.Fatal(err)
}
}
import (
"bytes"
- "io/ioutil"
+ "io"
"reflect"
"strings"
"testing"
data := &Block{Bytes: make([]byte, 65536)}
b.SetBytes(int64(len(data.Bytes)))
for i := 0; i < b.N; i++ {
- Encode(ioutil.Discard, data)
+ Encode(io.Discard, data)
}
}
"fmt"
"internal/testenv"
"io"
- "io/ioutil"
"os"
"os/exec"
"runtime"
func TestParseError(t *testing.T) {
for _, typ := range []string{"bool", "int", "int64", "uint", "uint64", "float64", "duration"} {
fs := NewFlagSet("parse error test", ContinueOnError)
- fs.SetOutput(ioutil.Discard)
+ fs.SetOutput(io.Discard)
_ = fs.Bool("bool", false, "")
_ = fs.Int("int", 0, "")
_ = fs.Int64("int64", 0, "")
}
for _, arg := range bad {
fs := NewFlagSet("parse error test", ContinueOnError)
- fs.SetOutput(ioutil.Discard)
+ fs.SetOutput(io.Discard)
_ = fs.Int("int", 0, "")
_ = fs.Int64("int64", 0, "")
_ = fs.Uint("uint", 0, "")
// Excluded for now: Standard gccgo doesn't support this import format currently.
// case goimporterMagic:
// var data []byte
- // data, err = ioutil.ReadAll(reader)
+ // data, err = io.ReadAll(reader)
// if err != nil {
// return
// }
"go/token"
"go/types"
"io"
- "io/ioutil"
"os"
"path/filepath"
"strings"
case "$$B\n":
var data []byte
- data, err = ioutil.ReadAll(buf)
+ data, err = io.ReadAll(buf)
if err != nil {
break
}
return s.Bytes(), nil
}
case io.Reader:
- return ioutil.ReadAll(s)
+ return io.ReadAll(s)
}
return nil, errors.New("invalid source")
}
initialize()
}
for i := 0; i < b.N; i++ {
- testprint(ioutil.Discard, testfile)
+ testprint(io.Discard, testfile)
}
}
"go/scanner"
"go/token"
"go/types"
- "io/ioutil"
+ "io"
"os"
"path/filepath"
"sync"
}
func parseStdin() (*ast.File, error) {
- src, err := ioutil.ReadAll(os.Stdin)
+ src, err := io.ReadAll(os.Stdin)
if err != nil {
return nil, err
}
"bytes"
"errors"
"fmt"
- "io/ioutil"
+ "io"
"strings"
"sync"
"testing"
t.Error("adding a template to a clone added it to the original")
}
// double check that the embedded template isn't available in the original
- err := t0.ExecuteTemplate(ioutil.Discard, "a", nil)
+ err := t0.ExecuteTemplate(io.Discard, "a", nil)
if err == nil {
t.Error("expected 'no such template' error")
}
// get the expected error output (no clone)
uncloned := Must(New("").Funcs(funcs).Parse("{{customFunc}}"))
- wantErr := uncloned.Execute(ioutil.Discard, nil)
+ wantErr := uncloned.Execute(io.Discard, nil)
// toClone must be the same as uncloned. It has to be recreated from scratch,
// since cloning cannot occur after execution.
toClone := Must(New("").Funcs(funcs).Parse("{{customFunc}}"))
cloned := Must(toClone.Clone())
- gotErr := cloned.Execute(ioutil.Discard, nil)
+ gotErr := cloned.Execute(io.Discard, nil)
if wantErr.Error() != gotErr.Error() {
t.Errorf("clone error message mismatch want %q got %q", wantErr, gotErr)
go func() {
defer wg.Done()
for i := 0; i < 100; i++ {
- if err := tmpl.Execute(ioutil.Discard, "data"); err != nil {
+ if err := tmpl.Execute(io.Discard, "data"); err != nil {
panic(err)
}
}
tmpl = Must(tmpl.Clone())
Must(tmpl.Parse(`{{define "B"}}Text{{end}}`))
for i := 0; i < 10; i++ {
- tmpl.Execute(ioutil.Discard, nil)
+ tmpl.Execute(io.Discard, nil)
}
if len(tmpl.DefinedTemplates()) > 200 {
t.Fatalf("too many templates: %v", len(tmpl.DefinedTemplates()))
for i := 0; i < 2; i++ {
t2 := Must(t1.Clone())
t2 = Must(t2.New(fmt.Sprintf("%d", i)).Parse(page))
- err := t2.Execute(ioutil.Discard, nil)
+ err := t2.Execute(io.Discard, nil)
if err != nil {
t.Fatal(err)
}
"errors"
"flag"
"fmt"
- "io/ioutil"
+ "io"
"reflect"
"strings"
"testing"
if err != nil {
t.Fatal(err)
}
- err = tmpl.Execute(ioutil.Discard, 0)
+ err = tmpl.Execute(io.Discard, 0)
if err == nil {
t.Fatal("expected error; got none")
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
tmpl := Must(New("tmpl").Parse(tc.src))
- err := tmpl.Execute(ioutil.Discard, tc.value)
+ err := tmpl.Execute(io.Discard, tc.value)
got := "<nil>"
if err != nil {
got = err.Error()
t.Skip("skipping in -short mode")
}
tmpl := Must(New("tmpl").Parse(`{{template "tmpl" .}}`))
- err := tmpl.Execute(ioutil.Discard, nil)
+ err := tmpl.Execute(io.Discard, nil)
got := "<nil>"
if err != nil {
got = err.Error()
"image/color/palette"
"image/draw"
_ "image/png"
- "io/ioutil"
+ "io"
"math/rand"
"os"
"reflect"
Image: images,
Delay: make([]int, 1),
}
- if err := EncodeAll(ioutil.Discard, g0); err == nil {
+ if err := EncodeAll(io.Discard, g0); err == nil {
t.Error("expected error from mismatched delay and image slice lengths")
}
for i := range g1.Disposal {
g1.Disposal[i] = DisposalNone
}
- if err := EncodeAll(ioutil.Discard, g1); err == nil {
+ if err := EncodeAll(io.Discard, g1); err == nil {
t.Error("expected error from mismatched disposal and image slice lengths")
}
}
func TestEncodeZeroGIF(t *testing.T) {
- if err := EncodeAll(ioutil.Discard, &GIF{}); err == nil {
+ if err := EncodeAll(io.Discard, &GIF{}); err == nil {
t.Error("expected error from providing empty gif")
}
}
Height: upperBound,
},
}
- err := EncodeAll(ioutil.Discard, g)
+ err := EncodeAll(io.Discard, g)
if upperBound >= 8 {
if err != nil {
t.Errorf("upperBound=%d: %v", upperBound, err)
Image: images,
Delay: make([]int, len(images)),
}
- err := EncodeAll(ioutil.Discard, g)
+ err := EncodeAll(io.Discard, g)
if lowerBound >= 0 {
if err != nil {
t.Errorf("lowerBound=%d: %v", lowerBound, err)
}
}
- err := EncodeAll(ioutil.Discard, &GIF{
+ err := EncodeAll(io.Discard, &GIF{
Image: []*image.Paletted{
image.NewPaletted(image.Rect(0, 0, w, h), pal),
},
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
- Encode(ioutil.Discard, paletted, nil)
+ Encode(io.Discard, paletted, nil)
}
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
- Encode(ioutil.Discard, rgba, nil)
+ Encode(io.Discard, rgba, nil)
}
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
- Encode(ioutil.Discard, paletted, nil)
+ Encode(io.Discard, paletted, nil)
}
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
- Encode(ioutil.Discard, rgba, nil)
+ Encode(io.Discard, rgba, nil)
}
}
"image"
"image/color"
"image/png"
- "io/ioutil"
+ "io"
"math/rand"
"os"
"testing"
b.ResetTimer()
options := &Options{Quality: 90}
for i := 0; i < b.N; i++ {
- Encode(ioutil.Discard, img, options)
+ Encode(io.Discard, img, options)
}
}
b.ResetTimer()
options := &Options{Quality: 90}
for i := 0; i < b.N; i++ {
- Encode(ioutil.Discard, img, options)
+ Encode(io.Discard, img, options)
}
}
"image"
"image/color"
"io"
- "io/ioutil"
"testing"
)
t.Error(err)
return
}
- n, err := io.Copy(ioutil.Discard, r)
+ n, err := io.Copy(io.Discard, r)
if err != nil {
t.Errorf("got error while reading image data: %v", err)
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
- Encode(ioutil.Discard, img)
+ Encode(io.Discard, img)
}
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
- e.Encode(ioutil.Discard, img)
+ e.Encode(io.Discard, img)
}
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
- Encode(ioutil.Discard, img)
+ Encode(io.Discard, img)
}
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
- Encode(ioutil.Discard, img)
+ Encode(io.Discard, img)
}
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
- Encode(ioutil.Discard, img)
+ Encode(io.Discard, img)
}
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
- Encode(ioutil.Discard, img)
+ Encode(io.Discard, img)
}
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
- Encode(ioutil.Discard, img)
+ Encode(io.Discard, img)
}
}
return nil, err
}
defer f.Close()
- return ioutil.ReadAll(base64.NewDecoder(base64.StdEncoding, f))
+ return io.ReadAll(base64.NewDecoder(base64.StdEncoding, f))
}
"compress/gzip"
"fmt"
"io"
- "io/ioutil"
"regexp"
"strings"
"time"
// may be a gzip-compressed encoded protobuf or one of many legacy
// profile formats which may be unsupported in the future.
func Parse(r io.Reader) (*Profile, error) {
- orig, err := ioutil.ReadAll(r)
+ orig, err := io.ReadAll(r)
if err != nil {
return nil, err
}
if err != nil {
return nil, fmt.Errorf("decompressing profile: %v", err)
}
- data, err := ioutil.ReadAll(gz)
+ data, err := io.ReadAll(gz)
if err != nil {
return nil, fmt.Errorf("decompressing profile: %v", err)
}
"bytes"
"fmt"
"io"
- "io/ioutil"
"log"
"os"
"strings"
r = io.TeeReader(r, os.Stdout)
// Everything read from r will be copied to stdout.
- ioutil.ReadAll(r)
+ io.ReadAll(r)
// Output:
// some io.Reader stream to be read
func ExampleReadAll() {
r := strings.NewReader("Go is a general-purpose language designed with systems programming in mind.")
- b, err := ioutil.ReadAll(r)
+ b, err := io.ReadAll(r)
if err != nil {
log.Fatal(err)
}
type discard struct{}
// discard implements ReaderFrom as an optimization so Copy to
-// ioutil.Discard can avoid doing unnecessary work.
+// io.Discard can avoid doing unnecessary work.
var _ ReaderFrom = discard{}
func (discard) Write(p []byte) (int, error) {
"errors"
"fmt"
. "io"
- "io/ioutil"
"runtime"
"strings"
"testing"
}
}
-// writerFunc is an io.Writer implemented by the underlying func.
+// writerFunc is an Writer implemented by the underlying func.
type writerFunc func(p []byte) (int, error)
func (f writerFunc) Write(p []byte) (int, error) {
slice := []Reader{strings.NewReader("hello world")}
r := MultiReader(slice...)
slice[0] = nil
- data, err := ioutil.ReadAll(r)
+ data, err := ReadAll(r)
if err != nil || string(data) != "hello world" {
t.Errorf("ReadAll() = %q, %v, want %q, nil", data, err, "hello world")
}
}
}
-// readerFunc is an io.Reader implemented by the underlying func.
+// readerFunc is an Reader implemented by the underlying func.
type readerFunc func(p []byte) (int, error)
func (f readerFunc) Read(p []byte) (int, error) {
}
// byteAndEOFReader is a Reader which reads one byte (the underlying
-// byte) and io.EOF at once in its Read call.
+// byte) and EOF at once in its Read call.
type byteAndEOFReader byte
func (b byteAndEOFReader) Read(p []byte) (n int, err error) {
// This used to yield bytes forever; issue 16795.
func TestMultiReaderSingleByteWithEOF(t *testing.T) {
- got, err := ioutil.ReadAll(LimitReader(MultiReader(byteAndEOFReader('a'), byteAndEOFReader('b')), 10))
+ got, err := ReadAll(LimitReader(MultiReader(byteAndEOFReader('a'), byteAndEOFReader('b')), 10))
if err != nil {
t.Fatal(err)
}
import (
"errors"
"io"
- "io/ioutil"
"strings"
"testing"
)
if charset != test.charsets[i] {
t.Errorf("DecodeHeader(%q), got charset %q, want %q", test.src, charset, test.charsets[i])
}
- content, err := ioutil.ReadAll(input)
+ content, err := io.ReadAll(input)
if err != nil {
t.Errorf("DecodeHeader(%q), error in reader: %v", test.src, err)
}
"bytes"
"fmt"
"io"
- "io/ioutil"
"mime"
)
// Fake character set for example.
// Real use would integrate with packages such
// as code.google.com/p/go-charset
- content, err := ioutil.ReadAll(input)
+ content, err := io.ReadAll(input)
if err != nil {
return nil, err
}
// Fake character set for example.
// Real use would integrate with packages such
// as code.google.com/p/go-charset
- content, err := ioutil.ReadAll(input)
+ content, err := io.ReadAll(input)
if err != nil {
return nil, err
}
import (
"fmt"
"io"
- "io/ioutil"
"log"
"mime"
"mime/multipart"
if err != nil {
log.Fatal(err)
}
- slurp, err := ioutil.ReadAll(p)
+ slurp, err := io.ReadAll(p)
if err != nil {
log.Fatal(err)
}
"bytes"
"fmt"
"io"
- "io/ioutil"
"mime"
"mime/quotedprintable"
"net/textproto"
}
func (p *Part) Close() error {
- io.Copy(ioutil.Discard, p)
+ io.Copy(io.Discard, p)
return nil
}
"encoding/json"
"fmt"
"io"
- "io/ioutil"
"net/textproto"
"os"
"reflect"
if err != nil {
t.Fatalf("didn't get a part")
}
- _, err = io.Copy(ioutil.Discard, part)
+ _, err = io.Copy(io.Discard, part)
if err != io.ErrUnexpectedEOF {
t.Fatalf("expected error io.ErrUnexpectedEOF; got %v", err)
}
if !reflect.DeepEqual(part.Header, hdr) {
t.Errorf("Part %d: part.Header = %v, want %v", i, part.Header, hdr)
}
- data, err := ioutil.ReadAll(part)
+ data, err := io.ReadAll(part)
expectEq(t, body, string(data), fmt.Sprintf("Part %d body", i))
if err != nil {
t.Fatalf("Part %d: ReadAll failed: %v", i, err)
if err != nil {
t.Fatalf("reading text/plain part: %v", err)
}
- if b, err := ioutil.ReadAll(p); string(b) != "*body*\r\n" || err != nil {
+ if b, err := io.ReadAll(p); string(b) != "*body*\r\n" || err != nil {
t.Fatalf("reading text/plain part: got %q, %v", b, err)
}
p, err = mr2.NextPart()
if err != nil {
t.Fatalf("reading text/html part: %v", err)
}
- if b, err := ioutil.ReadAll(p); string(b) != "<b>body</b>\r\n" || err != nil {
+ if b, err := io.ReadAll(p); string(b) != "<b>body</b>\r\n" || err != nil {
t.Fatalf("reading text/html part: got %q, %v", b, err)
}
t.Errorf("in test %q, NextPart: %v", tt.name, err)
continue Cases
}
- pbody, err := ioutil.ReadAll(p)
+ pbody, err := io.ReadAll(p)
if err != nil {
t.Errorf("in test %q, error reading part: %v", tt.name, err)
continue Cases
if err != nil {
return nil, fmt.Errorf("NextPart: %v", err)
}
- pbody, err := ioutil.ReadAll(p)
+ pbody, err := io.ReadAll(p)
if err != nil {
return nil, fmt.Errorf("error reading part: %v", err)
}
import (
"bytes"
- "io/ioutil"
+ "io"
"mime"
"net/textproto"
"strings"
if g, e := part.FormName(), "myfile"; g != e {
t.Errorf("part 1: want form name %q, got %q", e, g)
}
- slurp, err := ioutil.ReadAll(part)
+ slurp, err := io.ReadAll(part)
if err != nil {
t.Fatalf("part 1: ReadAll: %v", err)
}
if g, e := part.FormName(), "key"; g != e {
t.Errorf("part 2: want form name %q, got %q", e, g)
}
- slurp, err = ioutil.ReadAll(part)
+ slurp, err = io.ReadAll(part)
if err != nil {
t.Fatalf("part 2: ReadAll: %v", err)
}
// different goroutines. This was previously broken by
// https://codereview.appspot.com/95760043/ and reverted in
// https://codereview.appspot.com/117600043/
- w := NewWriter(ioutil.Discard)
+ w := NewWriter(io.Discard)
done := make(chan int)
go func() {
w.CreateFormField("foo")
import (
"fmt"
- "io/ioutil"
+ "io"
"mime/quotedprintable"
"os"
"strings"
`invalid escape: <b style="font-size: 200%">hello</b>`,
"Hello, Gophers! This symbol will be unescaped: =3D and this will be written in =\r\none line.",
} {
- b, err := ioutil.ReadAll(quotedprintable.NewReader(strings.NewReader(s)))
+ b, err := io.ReadAll(quotedprintable.NewReader(strings.NewReader(s)))
fmt.Printf("%s %v\n", b, err)
}
// Output:
import (
"bytes"
- "io/ioutil"
+ "io"
"strings"
"testing"
)
}
r := NewReader(buf)
- gotBytes, err := ioutil.ReadAll(r)
+ gotBytes, err := io.ReadAll(r)
if err != nil {
t.Fatalf("Error while reading from Reader: %v", err)
}
func BenchmarkWriter(b *testing.B) {
for i := 0; i < b.N; i++ {
- w := NewWriter(ioutil.Discard)
+ w := NewWriter(io.Discard)
w.Write(testMsg)
w.Close()
}
"crypto/x509"
"fmt"
"io"
- "io/ioutil"
. "net/http"
"net/http/httptest"
"strings"
if err != nil {
t.Fatal(err)
}
- body, err := ioutil.ReadAll(res.Body)
+ body, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
t.Fatal(err)
}
conn.Write([]byte("GET /foo\n"))
- body, err := ioutil.ReadAll(conn)
+ body, err := io.ReadAll(conn)
if err != nil {
t.Fatal(err)
}
"errors"
"fmt"
"io"
- "io/ioutil"
"net"
"net/http"
"net/url"
return nil, err
}
if r.ContentLength > 0 {
- r.Body = ioutil.NopCloser(io.LimitReader(os.Stdin, r.ContentLength))
+ r.Body = io.NopCloser(io.LimitReader(os.Stdin, r.ContentLength))
}
return r, nil
}
"errors"
"fmt"
"io"
- "io/ioutil"
"log"
"net/url"
"reflect"
if resp.ContentLength > 0 && req.Method != "HEAD" {
return nil, didTimeout, fmt.Errorf("http: RoundTripper implementation (%T) returned a *Response with content length %d but a nil Body", rt, resp.ContentLength)
}
- resp.Body = ioutil.NopCloser(strings.NewReader(""))
+ resp.Body = io.NopCloser(strings.NewReader(""))
}
if !deadline.IsZero() {
resp.Body = &cancelTimerBody{
// fails, the Transport won't reuse it anyway.
const maxBodySlurpSize = 2 << 10
if resp.ContentLength == -1 || resp.ContentLength <= maxBodySlurpSize {
- io.CopyN(ioutil.Discard, resp.Body, maxBodySlurpSize)
+ io.CopyN(io.Discard, resp.Body, maxBodySlurpSize)
}
resp.Body.Close()
"errors"
"fmt"
"io"
- "io/ioutil"
"log"
"net"
. "net/http"
fmt.Fprintf(w, "User-agent: go\nDisallow: /something/")
})
-// pedanticReadAll works like ioutil.ReadAll but additionally
+// pedanticReadAll works like io.ReadAll but additionally
// verifies that r obeys the documented io.Reader contract.
func pedanticReadAll(r io.Reader) (b []byte, err error) {
var bufa [64]byte
if g, e := tr.req.ContentLength, int64(len(expectedBody)); g != e {
t.Errorf("got ContentLength %d, want %d", g, e)
}
- bodyb, err := ioutil.ReadAll(tr.req.Body)
+ bodyb, err := io.ReadAll(tr.req.Body)
if err != nil {
t.Fatalf("ReadAll on req.Body: %v", err)
}
var ts *httptest.Server
ts = httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
log.Lock()
- slurp, _ := ioutil.ReadAll(r.Body)
+ slurp, _ := io.ReadAll(r.Body)
fmt.Fprintf(&log.Buffer, "%s %s %q", r.Method, r.RequestURI, slurp)
if cl := r.Header.Get("Content-Length"); r.Method == "GET" && len(slurp) == 0 && (r.ContentLength != 0 || cl != "") {
fmt.Fprintf(&log.Buffer, " (but with body=%T, content-length = %v, %q)", r.Body, r.ContentLength, cl)
for _, tt := range table {
content := tt.redirectBody
req, _ := NewRequest(method, ts.URL+tt.suffix, strings.NewReader(content))
- req.GetBody = func() (io.ReadCloser, error) { return ioutil.NopCloser(strings.NewReader(content)), nil }
+ req.GetBody = func() (io.ReadCloser, error) { return io.NopCloser(strings.NewReader(content)), nil }
res, err := c.Do(req)
if err != nil {
t.Errorf("status = %d; want %d", res.StatusCode, StatusFound)
}
defer res.Body.Close()
- slurp, err := ioutil.ReadAll(res.Body)
+ slurp, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
if res.ContentLength != tt.want {
t.Errorf("Content-Length = %d; want %d", res.ContentLength, tt.want)
}
- bs, err := ioutil.ReadAll(res.Body)
+ bs, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
errc := make(chan error, 1)
go func() {
- _, err := ioutil.ReadAll(res.Body)
+ _, err := io.ReadAll(res.Body)
errc <- err
res.Body.Close()
}()
t.Fatal(err)
}
cancel()
- _, err = io.Copy(ioutil.Discard, res.Body)
+ _, err = io.Copy(io.Discard, res.Body)
if err != ExportErrRequestCanceled {
t.Fatalf("error = %v; want errRequestCanceled", err)
}
if err != nil {
t.Fatal(err)
}
- _, err = ioutil.ReadAll(res.Body)
+ _, err = io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
t.Fatal(err)
resp := &Response{
StatusCode: 303,
Header: map[string][]string{"Location": {"http://www.example.com/"}},
- Body: ioutil.NopCloser(strings.NewReader("")),
+ Body: io.NopCloser(strings.NewReader("")),
}
return resp, nil
}
if resp.StatusCode != 200 {
t.Fatal(resp.Status)
}
- if got, err := ioutil.ReadAll(resp.Body); err != nil || string(got) != wantBody {
+ if got, err := io.ReadAll(resp.Body); err != nil || string(got) != wantBody {
t.Errorf("body = %q; want %q", got, wantBody)
}
}
}
}()
- if b, err := ioutil.ReadAll(resp.Body); err != nil {
+ if b, err := io.ReadAll(resp.Body); err != nil {
t.Errorf("read error from substitute Response.Body: %v", err)
} else if len(b) != 0 {
t.Errorf("substitute Response.Body was unexpectedly non-empty: %q", b)
"fmt"
"hash"
"io"
- "io/ioutil"
"log"
"net"
. "net/http"
t.t.Fatal(err)
}
defer res.Body.Close()
- slurp, err := ioutil.ReadAll(res.Body)
+ slurp, err := io.ReadAll(res.Body)
if err != nil {
t.t.Fatal(err)
}
func testChunkedResponseHeaders(t *testing.T, h2 bool) {
defer afterTest(t)
- log.SetOutput(ioutil.Discard) // is noisy otherwise
+ log.SetOutput(io.Discard) // is noisy otherwise
defer log.SetOutput(os.Stderr)
cst := newClientServerTest(t, h2, HandlerFunc(func(w ResponseWriter, r *Request) {
w.Header().Set("Content-Length", "intentional gibberish") // we check that this is deleted
} else {
t.Errorf("got %q response; want %q", res.Proto, wantProto)
}
- slurp, err := ioutil.ReadAll(res.Body)
+ slurp, err := io.ReadAll(res.Body)
res.Body.Close()
res.Body = slurpResult{
- ReadCloser: ioutil.NopCloser(bytes.NewReader(slurp)),
+ ReadCloser: io.NopCloser(bytes.NewReader(slurp)),
body: slurp,
err: err,
}
if len(res.TransferEncoding) > 0 {
t.Errorf("expected no TransferEncoding; got %v", res.TransferEncoding)
}
- body, err := ioutil.ReadAll(res.Body)
+ body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
close(cancel)
- rest, err := ioutil.ReadAll(res.Body)
+ rest, err := io.ReadAll(res.Body)
all := string(firstRead) + string(rest)
if all != "Hello" {
t.Errorf("Read %q (%q + %q); want Hello", all, firstRead, rest)
}
sort.Strings(decl)
- slurp, err := ioutil.ReadAll(r.Body)
+ slurp, err := io.ReadAll(r.Body)
if err != nil {
t.Errorf("Server reading request body: %v", err)
}
t.Fatal(err)
}
res.Body.Close()
- data, err := ioutil.ReadAll(res.Body)
+ data, err := io.ReadAll(res.Body)
if len(data) != 0 || err == nil {
t.Fatalf("ReadAll returned %q, %v; want error", data, err)
}
// Read in one goroutine.
go func() {
defer wg.Done()
- data, err := ioutil.ReadAll(r.Body)
+ data, err := io.ReadAll(r.Body)
if string(data) != reqBody {
t.Errorf("Handler read %q; want %q", data, reqBody)
}
if err != nil {
t.Fatal(err)
}
- data, err := ioutil.ReadAll(res.Body)
+ data, err := io.ReadAll(res.Body)
defer res.Body.Close()
if err != nil {
t.Fatal(err)
t.Errorf("%d. RoundTrip = %v", i, err)
continue
}
- slurp, err := ioutil.ReadAll(res.Body)
+ slurp, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
t.Errorf("%d. read body = %v", i, err)
}
}
defer resp.Body.Close()
- slurp, err := ioutil.ReadAll(resp.Body)
+ slurp, err := io.ReadAll(resp.Body)
if err != nil {
t.Error(err)
}
setParallel(t)
defer afterTest(t)
cst := newClientServerTest(t, h2, HandlerFunc(func(w ResponseWriter, r *Request) {
- ioutil.ReadAll(r.Body)
+ io.ReadAll(r.Body)
if body {
io.WriteString(w, "Hello.")
}
if err != nil {
t.Fatal(err)
}
- if _, err := ioutil.ReadAll(res.Body); err != nil {
+ if _, err := io.ReadAll(res.Body); err != nil {
t.Fatal(err)
}
if err := res.Body.Close(); err != nil {
res, err := cst.c.Do(req)
var body []byte
if err == nil {
- body, _ = ioutil.ReadAll(res.Body)
+ body, _ = io.ReadAll(res.Body)
res.Body.Close()
}
var dialed bool
}
gotHeaders <- true
defer res.Body.Close()
- slurp, err := ioutil.ReadAll(res.Body)
+ slurp, err := io.ReadAll(res.Body)
if string(slurp) != msg {
t.Errorf("client read %q; want %q", slurp, msg)
}
if err != nil {
t.Fatal(err)
}
- if _, err := io.Copy(ioutil.Discard, res.Body); err != nil {
+ if _, err := io.Copy(io.Discard, res.Body); err != nil {
t.Fatal(err)
}
res.Body.Close()
func TestBadResponseAfterReadingBody(t *testing.T) {
defer afterTest(t)
cst := newClientServerTest(t, false, HandlerFunc(func(w ResponseWriter, r *Request) {
- _, err := io.Copy(ioutil.Discard, r.Body)
+ _, err := io.Copy(io.Discard, r.Body)
if err != nil {
t.Fatal(err)
}
t.Fatal(err)
}
defer res.Body.Close()
- body, err := ioutil.ReadAll(res.Body)
+ body, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
// handle error
}
defer resp.Body.Close()
- body, err := ioutil.ReadAll(resp.Body)
+ body, err := io.ReadAll(resp.Body)
// ...
For control over HTTP client headers, redirect policy, and other
"context"
"fmt"
"io"
- "io/ioutil"
"log"
"net/http"
"os"
if err != nil {
log.Fatal(err)
}
- robots, err := ioutil.ReadAll(res.Body)
+ robots, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
log.Fatal(err)
"errors"
"fmt"
"io"
- "io/ioutil"
"net"
"net/http"
"net/http/cgi"
var errCloseConn = errors.New("fcgi: connection should be closed")
-var emptyBody = ioutil.NopCloser(strings.NewReader(""))
+var emptyBody = io.NopCloser(strings.NewReader(""))
// ErrRequestAborted is returned by Read when a handler attempts to read the
// body of a request that has been aborted by the web server.
// some sort of abort request to the host, so the host
// can properly cut off the client sending all the data.
// For now just bound it a little and
- io.CopyN(ioutil.Discard, body, 100<<20)
+ io.CopyN(io.Discard, body, 100<<20)
body.Close()
if !req.keepConn {
"bytes"
"errors"
"io"
- "io/ioutil"
"net/http"
"strings"
"testing"
r *http.Request,
) {
// block on reading body of request
- _, err := io.Copy(ioutil.Discard, r.Body)
+ _, err := io.Copy(io.Discard, r.Body)
if err != tt.err {
t.Errorf("Expected %#v, got %#v", tt.err, err)
}
// end of params
1, 4, 0, 1, 0, 0, 0, 0,
}
- rw := rwNopCloser{bytes.NewReader(input), ioutil.Discard}
+ rw := rwNopCloser{bytes.NewReader(input), io.Discard}
c := newChild(rw, http.DefaultServeMux)
c.serve()
}
package http
import (
+ "io"
"io/ioutil"
"os"
"path/filepath"
if res.Body == nil {
t.Fatalf("for %s, nil Body", urlstr)
}
- slurp, err := ioutil.ReadAll(res.Body)
+ slurp, err := io.ReadAll(res.Body)
res.Body.Close()
check("ReadAll "+urlstr, err)
if string(slurp) != "Bar" {
if g, w := part.Header.Get("Content-Range"), wantContentRange; g != w {
t.Errorf("range=%q: part Content-Range = %q; want %q", rt.r, g, w)
}
- body, err := ioutil.ReadAll(part)
+ body, err := io.ReadAll(part)
if err != nil {
t.Errorf("range=%q, reading part index %d body: %v", rt.r, ri, err)
continue Cases
if err != nil {
t.Fatalf("test %q: Get: %v", test.name, err)
}
- b, err := ioutil.ReadAll(res.Body)
+ b, err := io.ReadAll(res.Body)
if err != nil {
t.Fatalf("test %q: read Body: %v", test.name, err)
}
}
defer res.Body.Close()
- b, err := ioutil.ReadAll(res.Body)
+ b, err := io.ReadAll(res.Body)
if err != nil {
t.Fatalf("read Body: %v", err)
}
if err != nil {
t.Fatalf("Get %s: %v", suffix, err)
}
- b, err := ioutil.ReadAll(res.Body)
+ b, err := io.ReadAll(res.Body)
if err != nil {
t.Fatalf("ReadAll %s: %v", suffix, err)
}
if err != nil {
t.Fatal(err)
}
- b, err := ioutil.ReadAll(res.Body)
+ b, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal("reading Body:", err)
}
if err != nil {
t.Fatal(err)
}
- b, err := ioutil.ReadAll(res.Body)
+ b, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
if err != nil {
t.Fatal(err)
}
- io.Copy(ioutil.Discard, res.Body)
+ io.Copy(io.Discard, res.Body)
res.Body.Close()
if res.StatusCode != tt.wantStatus {
t.Errorf("test %q using %q: got status = %d; want %d", testName, method, res.StatusCode, tt.wantStatus)
if err != nil {
t.Fatalf("http client error: %v", err)
}
- _, err = io.Copy(ioutil.Discard, res.Body)
+ _, err = io.Copy(io.Discard, res.Body)
if err != nil {
t.Fatalf("client body read error: %v", err)
}
if err != nil {
t.Fatalf("%s: for URL %q, send error: %v", testName, req.URL.String(), err)
}
- b, err := ioutil.ReadAll(r.Body)
+ b, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("%s: for URL %q, reading body: %v", testName, req.URL.String(), err)
}
if g, w := res.StatusCode, tt.wantCode; g != w {
t.Errorf("StatusCode mismatch: got %d want %d", g, w)
}
- slurp, err := ioutil.ReadAll(res.Body)
+ slurp, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
t.Fatal(err)
import (
"fmt"
"io"
- "io/ioutil"
"log"
"net/http"
"net/http/httptest"
handler(w, req)
resp := w.Result()
- body, _ := ioutil.ReadAll(resp.Body)
+ body, _ := io.ReadAll(resp.Body)
fmt.Println(resp.StatusCode)
fmt.Println(resp.Header.Get("Content-Type"))
if err != nil {
log.Fatal(err)
}
- greeting, err := ioutil.ReadAll(res.Body)
+ greeting, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
log.Fatal(err)
if err != nil {
log.Fatal(err)
}
- greeting, err := ioutil.ReadAll(res.Body)
+ greeting, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
log.Fatal(err)
log.Fatal(err)
}
- greeting, err := ioutil.ReadAll(res.Body)
+ greeting, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
log.Fatal(err)
"bytes"
"crypto/tls"
"io"
- "io/ioutil"
"net/http"
"strings"
)
if rc, ok := body.(io.ReadCloser); ok {
req.Body = rc
} else {
- req.Body = ioutil.NopCloser(body)
+ req.Body = io.NopCloser(body)
}
}
import (
"crypto/tls"
"io"
- "io/ioutil"
"net/http"
"net/url"
"reflect"
} {
t.Run(tt.name, func(t *testing.T) {
got := NewRequest(tt.method, tt.uri, tt.body)
- slurp, err := ioutil.ReadAll(got.Body)
+ slurp, err := io.ReadAll(got.Body)
if err != nil {
t.Errorf("ReadAll: %v", err)
}
import (
"bytes"
"fmt"
- "io/ioutil"
+ "io"
"net/http"
"net/textproto"
"strconv"
}
res.Status = fmt.Sprintf("%03d %s", res.StatusCode, http.StatusText(res.StatusCode))
if rw.Body != nil {
- res.Body = ioutil.NopCloser(bytes.NewReader(rw.Body.Bytes()))
+ res.Body = io.NopCloser(bytes.NewReader(rw.Body.Bytes()))
} else {
res.Body = http.NoBody
}
import (
"fmt"
"io"
- "io/ioutil"
"net/http"
"testing"
)
}
hasResultContents := func(want string) checkFunc {
return func(rec *ResponseRecorder) error {
- contentBytes, err := ioutil.ReadAll(rec.Result().Body)
+ contentBytes, err := io.ReadAll(rec.Result().Body)
if err != nil {
return err
}
import (
"bufio"
- "io/ioutil"
+ "io"
"net"
"net/http"
"testing"
if err != nil {
t.Fatal(err)
}
- got, err := ioutil.ReadAll(res.Body)
+ got, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
t.Fatal(err)
if err != nil {
t.Fatal(err)
}
- got, err := ioutil.ReadAll(res.Body)
+ got, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
res, err = http.Get(ts.URL)
if err == nil {
- body, _ := ioutil.ReadAll(res.Body)
+ body, _ := io.ReadAll(res.Body)
t.Fatalf("Unexpected response after close: %v, %v, %s", res.Status, res.Header, body)
}
}
if err != nil {
t.Fatal(err)
}
- got, err := ioutil.ReadAll(res.Body)
+ got, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
t.Fatal(err)
"errors"
"fmt"
"io"
- "io/ioutil"
"net"
"net/http"
"net/url"
if err = b.Close(); err != nil {
return nil, b, err
}
- return ioutil.NopCloser(&buf), ioutil.NopCloser(bytes.NewReader(buf.Bytes())), nil
+ return io.NopCloser(&buf), io.NopCloser(bytes.NewReader(buf.Bytes())), nil
}
// dumpConn is a net.Conn which writes to Writer and reads from Reader
if !body {
contentLength := outgoingLength(req)
if contentLength != 0 {
- req.Body = ioutil.NopCloser(io.LimitReader(neverEnding('x'), contentLength))
+ req.Body = io.NopCloser(io.LimitReader(neverEnding('x'), contentLength))
dummyBody = true
}
} else {
if err == nil {
// Ensure all the body is read; otherwise
// we'll get a partial dump.
- io.Copy(ioutil.Discard, req.Body)
+ io.Copy(io.Discard, req.Body)
req.Body.Close()
}
select {
func (failureToReadBody) Close() error { return nil }
// emptyBody is an instance of empty reader.
-var emptyBody = ioutil.NopCloser(strings.NewReader(""))
+var emptyBody = io.NopCloser(strings.NewReader(""))
// DumpResponse is like DumpRequest but dumps a response.
func DumpResponse(resp *http.Response, body bool) ([]byte, error) {
"bytes"
"fmt"
"io"
- "io/ioutil"
"net/http"
"net/url"
"runtime"
}
switch b := ti.Body.(type) {
case []byte:
- req.Body = ioutil.NopCloser(bytes.NewReader(b))
+ req.Body = io.NopCloser(bytes.NewReader(b))
case func() io.ReadCloser:
req.Body = b()
default:
Header: http.Header{
"Foo": []string{"Bar"},
},
- Body: ioutil.NopCloser(strings.NewReader("foo")), // shouldn't be used
+ Body: io.NopCloser(strings.NewReader("foo")), // shouldn't be used
},
body: false, // to verify we see 50, not empty or 3.
want: `HTTP/1.1 200 OK
ProtoMajor: 1,
ProtoMinor: 1,
ContentLength: 3,
- Body: ioutil.NopCloser(strings.NewReader("foo")),
+ Body: io.NopCloser(strings.NewReader("foo")),
},
body: true,
want: `HTTP/1.1 200 OK
ProtoMajor: 1,
ProtoMinor: 1,
ContentLength: -1,
- Body: ioutil.NopCloser(strings.NewReader("foo")),
+ Body: io.NopCloser(strings.NewReader("foo")),
TransferEncoding: []string{"chunked"},
},
body: true,
import (
"fmt"
- "io/ioutil"
+ "io"
"log"
"net/http"
"net/http/httptest"
}
defer resp.Body.Close()
- b, err := ioutil.ReadAll(resp.Body)
+ b, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
log.Fatal(err)
}
- b, err := ioutil.ReadAll(resp.Body)
+ b, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
"errors"
"fmt"
"io"
- "io/ioutil"
"log"
"net/http"
"net/http/httptest"
t.Fatal(err)
}
proxyHandler := NewSingleHostReverseProxy(backendURL)
- proxyHandler.ErrorLog = log.New(ioutil.Discard, "", 0) // quiet for tests
+ proxyHandler.ErrorLog = log.New(io.Discard, "", 0) // quiet for tests
frontend := httptest.NewServer(proxyHandler)
defer frontend.Close()
frontendClient := frontend.Client()
if cookie := res.Cookies()[0]; cookie.Name != "flavor" {
t.Errorf("unexpected cookie %q", cookie.Name)
}
- bodyBytes, _ := ioutil.ReadAll(res.Body)
+ bodyBytes, _ := io.ReadAll(res.Body)
if g, e := string(bodyBytes), backendResponse; g != e {
t.Errorf("got body %q; expected %q", g, e)
}
t.Fatalf("Get: %v", err)
}
defer res.Body.Close()
- bodyBytes, err := ioutil.ReadAll(res.Body)
+ bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
t.Fatalf("reading body: %v", err)
}
if g, e := res.StatusCode, backendStatus; g != e {
t.Errorf("got res.StatusCode %d; expected %d", g, e)
}
- bodyBytes, _ := ioutil.ReadAll(res.Body)
+ bodyBytes, _ := io.ReadAll(res.Body)
if g, e := string(bodyBytes), backendResponse; g != e {
t.Errorf("got body %q; expected %q", g, e)
}
t.Fatalf("Get: %v", err)
}
defer res.Body.Close()
- if bodyBytes, _ := ioutil.ReadAll(res.Body); string(bodyBytes) != expected {
+ if bodyBytes, _ := io.ReadAll(res.Body); string(bodyBytes) != expected {
t.Errorf("got body %q; expected %q", bodyBytes, expected)
}
}
defer backend.Close()
- backend.Config.ErrorLog = log.New(ioutil.Discard, "", 0)
+ backend.Config.ErrorLog = log.New(io.Discard, "", 0)
backendURL, err := url.Parse(backend.URL)
if err != nil {
// Discards errors of the form:
// http: proxy error: read tcp 127.0.0.1:44643: use of closed network connection
- proxyHandler.ErrorLog = log.New(ioutil.Discard, "", 0)
+ proxyHandler.ErrorLog = log.New(io.Discard, "", 0)
frontend := httptest.NewServer(proxyHandler)
defer frontend.Close()
t.Fatal(err)
}
defer res.Body.Close()
- slurp, err := ioutil.ReadAll(res.Body)
+ slurp, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
t.Fatal(err)
}
proxyHandler := NewSingleHostReverseProxy(backendURL)
- proxyHandler.ErrorLog = log.New(ioutil.Discard, "", 0) // quiet for tests
+ proxyHandler.ErrorLog = log.New(io.Discard, "", 0) // quiet for tests
frontend := httptest.NewServer(proxyHandler)
defer frontend.Close()
frontendClient := frontend.Client()
if err != nil {
t.Fatalf("Get: %v", err)
}
- slurp, err := ioutil.ReadAll(res.Body)
+ slurp, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
t.Fatalf("reading body: %v", err)
const backendStatus = 200
var requestBody = bytes.Repeat([]byte("a"), 1<<20)
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- slurp, err := ioutil.ReadAll(r.Body)
+ slurp, err := io.ReadAll(r.Body)
if err != nil {
t.Errorf("Backend body read = %v", err)
}
if g, e := res.StatusCode, backendStatus; g != e {
t.Errorf("got res.StatusCode %d; expected %d", g, e)
}
- bodyBytes, _ := ioutil.ReadAll(res.Body)
+ bodyBytes, _ := io.ReadAll(res.Body)
if g, e := string(bodyBytes), backendResponse; g != e {
t.Errorf("got body %q; expected %q", g, e)
}
func TestReverseProxy_NilBody(t *testing.T) {
backendURL, _ := url.Parse("http://fake.tld/")
proxyHandler := NewSingleHostReverseProxy(backendURL)
- proxyHandler.ErrorLog = log.New(ioutil.Discard, "", 0) // quiet for tests
+ proxyHandler.ErrorLog = log.New(io.Discard, "", 0) // quiet for tests
proxyHandler.Transport = RoundTripperFunc(func(req *http.Request) (*http.Response, error) {
if req.Body != nil {
t.Error("Body != nil; want a nil Body")
// Issue 33142: always allocate the request headers
func TestReverseProxy_AllocatedHeader(t *testing.T) {
proxyHandler := new(ReverseProxy)
- proxyHandler.ErrorLog = log.New(ioutil.Discard, "", 0) // quiet for tests
- proxyHandler.Director = func(*http.Request) {} // noop
+ proxyHandler.ErrorLog = log.New(io.Discard, "", 0) // quiet for tests
+ proxyHandler.Director = func(*http.Request) {} // noop
proxyHandler.Transport = RoundTripperFunc(func(req *http.Request) (*http.Response, error) {
if req.Header == nil {
t.Error("Header == nil; want a non-nil Header")
rpURL, _ := url.Parse(backendServer.URL)
rproxy := NewSingleHostReverseProxy(rpURL)
- rproxy.ErrorLog = log.New(ioutil.Discard, "", 0) // quiet for tests
+ rproxy.ErrorLog = log.New(io.Discard, "", 0) // quiet for tests
rproxy.ModifyResponse = func(resp *http.Response) error {
if resp.Header.Get("X-Hit-Mod") != "true" {
return fmt.Errorf("tried to by-pass proxy")
if rproxy.Transport == nil {
rproxy.Transport = failingRoundTripper{}
}
- rproxy.ErrorLog = log.New(ioutil.Discard, "", 0) // quiet for tests
+ rproxy.ErrorLog = log.New(io.Discard, "", 0) // quiet for tests
if tt.errorHandler != nil {
rproxy.ErrorHandler = tt.errorHandler
}
func BenchmarkServeHTTP(b *testing.B) {
res := &http.Response{
StatusCode: 200,
- Body: ioutil.NopCloser(strings.NewReader("")),
+ Body: io.NopCloser(strings.NewReader("")),
}
proxy := &ReverseProxy{
Director: func(*http.Request) {},
// Issue 18327: verify we always do a deep copy of the Request.Header map
// before any mutations.
func TestClonesRequestHeaders(t *testing.T) {
- log.SetOutput(ioutil.Discard)
+ log.SetOutput(io.Discard)
defer log.SetOutput(os.Stderr)
req, _ := http.NewRequest("GET", "http://foo.tld/", nil)
req.RemoteAddr = "1.2.3.4:56789"
// Issue 23643: panic on body copy error
func TestReverseProxy_PanicBodyError(t *testing.T) {
- log.SetOutput(ioutil.Discard)
+ log.SetOutput(io.Discard)
defer log.SetOutput(os.Stderr)
backendServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
out := "this call was relayed by the reverse proxy"
backURL, _ := url.Parse(backendServer.URL)
rproxy := NewSingleHostReverseProxy(backURL)
- rproxy.ErrorLog = log.New(ioutil.Discard, "", 0) // quiet for tests
+ rproxy.ErrorLog = log.New(io.Discard, "", 0) // quiet for tests
rproxy.ModifyResponse = func(res *http.Response) error {
res.Header.Add("X-Modified", "true")
return nil
backendURL, _ := url.Parse(cst.URL)
rproxy := NewSingleHostReverseProxy(backendURL)
- rproxy.ErrorLog = log.New(ioutil.Discard, "", 0) // quiet for tests
+ rproxy.ErrorLog = log.New(io.Discard, "", 0) // quiet for tests
rproxy.ModifyResponse = func(res *http.Response) error {
res.Header.Add("X-Modified", "true")
return nil
t.Fatal(err)
}
proxyHandler := NewSingleHostReverseProxy(backendURL)
- proxyHandler.ErrorLog = log.New(ioutil.Discard, "", 0) // quiet for tests
+ proxyHandler.ErrorLog = log.New(io.Discard, "", 0) // quiet for tests
frontend := httptest.NewServer(proxyHandler)
defer frontend.Close()
frontendClient := frontend.Client()
t.Fatalf("Get: %v", err)
}
- ioutil.ReadAll(res.Body)
+ io.ReadAll(res.Body)
if g, w := res.Trailer.Get("X-Unannounced-Trailer"), "unannounced_trailer_value"; g != w {
t.Errorf("Trailer(X-Unannounced-Trailer) = %q; want %q", g, w)
"bytes"
"fmt"
"io"
- "io/ioutil"
"strings"
"testing"
)
}
r := NewChunkedReader(&b)
- data, err := ioutil.ReadAll(r)
+ data, err := io.ReadAll(r)
if err != nil {
t.Logf(`data: "%s"`, data)
t.Fatalf("ReadAll from reader: %v", err)
"17;someext\r\n" + // token without value
"world! 0123456789abcdef\r\n" +
"0;someextension=sometoken\r\n" // token=token
- data, err := ioutil.ReadAll(NewChunkedReader(strings.NewReader(in)))
+ data, err := io.ReadAll(NewChunkedReader(strings.NewReader(in)))
if err != nil {
t.Fatalf("ReadAll = %q, %v", data, err)
}
import (
"fmt"
- "io/ioutil"
+ "io"
"log"
"net/http"
"os"
"time"
)
-var quietLog = log.New(ioutil.Discard, "", 0)
+var quietLog = log.New(io.Discard, "", 0)
func TestMain(m *testing.M) {
v := m.Run()
"bytes"
"fmt"
"internal/profile"
- "io/ioutil"
+ "io"
"net/http"
"net/http/httptest"
"runtime"
t.Errorf("status code: got %d; want %d", got, want)
}
- body, err := ioutil.ReadAll(resp.Body)
+ body, err := io.ReadAll(resp.Body)
if err != nil {
t.Errorf("when reading response body, expected non-nil err; got %v", err)
}
return nil, fmt.Errorf("failed to fetch %q: %v", url, r.Status)
}
- b, err := ioutil.ReadAll(r.Body)
+ b, err := io.ReadAll(r.Body)
r.Body.Close()
if err != nil {
return nil, fmt.Errorf("failed to read and parse the result from %q: %v", url, err)
"bytes"
"fmt"
"io"
- "io/ioutil"
"net/url"
"reflect"
"strings"
for _, tt := range badRequestTests {
got, err := ReadRequest(bufio.NewReader(bytes.NewReader(tt.req)))
if err == nil {
- all, err := ioutil.ReadAll(got.Body)
+ all, err := io.ReadAll(got.Body)
t.Errorf("%s: got unexpected request = %#v\n Body = %q, %v", tt.name, got, all, err)
}
}
"errors"
"fmt"
"io"
- "io/ioutil"
"mime"
"mime/multipart"
"net"
}
rc, ok := body.(io.ReadCloser)
if !ok && body != nil {
- rc = ioutil.NopCloser(body)
+ rc = io.NopCloser(body)
}
// The host's colon:port should be normalized. See Issue 14836.
u.Host = removeEmptyPort(u.Host)
buf := v.Bytes()
req.GetBody = func() (io.ReadCloser, error) {
r := bytes.NewReader(buf)
- return ioutil.NopCloser(r), nil
+ return io.NopCloser(r), nil
}
case *bytes.Reader:
req.ContentLength = int64(v.Len())
snapshot := *v
req.GetBody = func() (io.ReadCloser, error) {
r := snapshot
- return ioutil.NopCloser(&r), nil
+ return io.NopCloser(&r), nil
}
case *strings.Reader:
req.ContentLength = int64(v.Len())
snapshot := *v
req.GetBody = func() (io.ReadCloser, error) {
r := snapshot
- return ioutil.NopCloser(&r), nil
+ return io.NopCloser(&r), nil
}
default:
// This is where we'd set it to -1 (at least
maxFormSize = int64(10 << 20) // 10 MB is a lot of text.
reader = io.LimitReader(r.Body, maxFormSize+1)
}
- b, e := ioutil.ReadAll(reader)
+ b, e := io.ReadAll(reader)
if e != nil {
if err == nil {
err = e
req := &Request{
Method: "POST",
Header: test.contentType,
- Body: ioutil.NopCloser(strings.NewReader("body")),
+ Body: io.NopCloser(strings.NewReader("body")),
}
err := req.ParseForm()
switch {
req := &Request{
Method: "POST",
Header: Header{"Content-Type": {test.contentType}},
- Body: ioutil.NopCloser(new(bytes.Buffer)),
+ Body: io.NopCloser(new(bytes.Buffer)),
}
multipart, err := req.MultipartReader()
if test.shouldError {
req := &Request{
Method: "POST",
Header: Header{"Content-Type": {`multipart/form-data; boundary=xxx`}},
- Body: ioutil.NopCloser(strings.NewReader(postData)),
+ Body: io.NopCloser(strings.NewReader(postData)),
}
initialFormItems := map[string]string{
req := &Request{
Method: "POST",
Header: Header{"Content-Type": {`multipart/form-data; boundary="foo123"`}},
- Body: ioutil.NopCloser(new(bytes.Buffer)),
+ Body: io.NopCloser(new(bytes.Buffer)),
}
err := req.ParseMultipartForm(25)
if err == nil {
}
func TestIssue10884_MaxBytesEOF(t *testing.T) {
- dst := ioutil.Discard
+ dst := io.Discard
_, err := io.Copy(dst, MaxBytesReader(
responseWriterJustWriter{dst},
- ioutil.NopCloser(delayedEOFReader{strings.NewReader("12345")}),
+ io.NopCloser(delayedEOFReader{strings.NewReader("12345")}),
5))
if err != nil {
t.Fatal(err)
2: {101, 100},
}
for i, tt := range tests {
- rc := MaxBytesReader(nil, ioutil.NopCloser(bytes.NewReader(make([]byte, tt.readable))), tt.limit)
+ rc := MaxBytesReader(nil, io.NopCloser(bytes.NewReader(make([]byte, tt.readable))), tt.limit)
if err := isSticky(rc); err != nil {
t.Errorf("%d. error: %v", i, err)
}
t.Errorf("test[%d]: GetBody = nil", i)
continue
}
- slurp1, err := ioutil.ReadAll(req.Body)
+ slurp1, err := io.ReadAll(req.Body)
if err != nil {
t.Errorf("test[%d]: ReadAll(Body) = %v", i, err)
}
if err != nil {
t.Errorf("test[%d]: GetBody = %v", i, err)
}
- slurp2, err := ioutil.ReadAll(newBody)
+ slurp2, err := io.ReadAll(newBody)
if err != nil {
t.Errorf("test[%d]: ReadAll(GetBody()) = %v", i, err)
}
func runFileAndServerBenchmarks(b *testing.B, tlsOption bool, f *os.File, n int64) {
handler := HandlerFunc(func(rw ResponseWriter, req *Request) {
defer req.Body.Close()
- nc, err := io.Copy(ioutil.Discard, req.Body)
+ nc, err := io.Copy(io.Discard, req.Body)
if err != nil {
panic(err)
}
}
b.StartTimer()
- req, err := NewRequest("PUT", cst.URL, ioutil.NopCloser(f))
+ req, err := NewRequest("PUT", cst.URL, io.NopCloser(f))
if err != nil {
b.Fatal(err)
}
"errors"
"fmt"
"io"
- "io/ioutil"
"net"
"net/url"
"strings"
ContentLength: 0, // as if unset by user
},
- Body: func() io.ReadCloser { return ioutil.NopCloser(io.LimitReader(strings.NewReader("xx"), 0)) },
+ Body: func() io.ReadCloser { return io.NopCloser(io.LimitReader(strings.NewReader("xx"), 0)) },
WantWrite: "POST / HTTP/1.1\r\n" +
"Host: example.com\r\n" +
ContentLength: 0, // as if unset by user
},
- Body: func() io.ReadCloser { return ioutil.NopCloser(io.LimitReader(strings.NewReader("xx"), 1)) },
+ Body: func() io.ReadCloser { return io.NopCloser(io.LimitReader(strings.NewReader("xx"), 1)) },
WantWrite: "POST / HTTP/1.1\r\n" +
"Host: example.com\r\n" +
Body: func() io.ReadCloser {
err := errors.New("Custom reader error")
errReader := iotest.ErrReader(err)
- return ioutil.NopCloser(io.MultiReader(strings.NewReader("x"), errReader))
+ return io.NopCloser(io.MultiReader(strings.NewReader("x"), errReader))
},
WantError: errors.New("Custom reader error"),
Body: func() io.ReadCloser {
err := errors.New("Custom reader error")
errReader := iotest.ErrReader(err)
- return ioutil.NopCloser(errReader)
+ return io.NopCloser(errReader)
},
WantError: errors.New("Custom reader error"),
}
switch b := tt.Body.(type) {
case []byte:
- tt.Req.Body = ioutil.NopCloser(bytes.NewReader(b))
+ tt.Req.Body = io.NopCloser(bytes.NewReader(b))
case func() io.ReadCloser:
tt.Req.Body = b()
}
},
{
method: "GET",
- body: ioutil.NopCloser(strings.NewReader("")),
+ body: io.NopCloser(strings.NewReader("")),
want: noContentLengthOrTransferEncoding,
},
{
method: "GET",
clen: -1,
- body: ioutil.NopCloser(strings.NewReader("")),
+ body: io.NopCloser(strings.NewReader("")),
want: noContentLengthOrTransferEncoding,
},
// A GET with a body, with explicit content length:
{
method: "GET",
clen: 7,
- body: ioutil.NopCloser(strings.NewReader("foobody")),
+ body: io.NopCloser(strings.NewReader("foobody")),
want: all(matchSubstr("Content-Length: 7"),
matchSubstr("foobody")),
},
{
method: "GET",
clen: -1,
- body: ioutil.NopCloser(strings.NewReader("foobody")),
+ body: io.NopCloser(strings.NewReader("foobody")),
want: all(matchSubstr("Transfer-Encoding: chunked"),
matchSubstr("\r\n1\r\nf\r\n"),
matchSubstr("oobody")),
{
method: "POST",
clen: -1,
- body: ioutil.NopCloser(strings.NewReader("foobody")),
+ body: io.NopCloser(strings.NewReader("foobody")),
want: all(matchSubstr("Transfer-Encoding: chunked"),
matchSubstr("foobody")),
},
{
method: "POST",
clen: -1,
- body: ioutil.NopCloser(strings.NewReader("")),
+ body: io.NopCloser(strings.NewReader("")),
want: all(matchSubstr("Transfer-Encoding: chunked")),
},
// Verify that a blocking Request.Body doesn't block forever.
tt.afterReqRead = func() {
pw.Close()
}
- tt.body = ioutil.NopCloser(pr)
+ tt.body = io.NopCloser(pr)
},
want: matchSubstr("Transfer-Encoding: chunked"),
},
}
// Ensure all the body is read; otherwise
// we'll get a partial dump.
- io.Copy(ioutil.Discard, req.Body)
+ io.Copy(io.Discard, req.Body)
req.Body.Close()
}
dr.c <- strings.NewReader("HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n")
"fmt"
"go/token"
"io"
- "io/ioutil"
"net/http/internal"
"net/url"
"reflect"
t.Errorf("#%d: %v", i, err)
continue
}
- err = resp.Write(ioutil.Discard)
+ err = resp.Write(io.Discard)
if err != nil {
t.Errorf("#%d: %v", i, err)
continue
}
resp.Body.Close()
- rest, err := ioutil.ReadAll(bufr)
+ rest, err := io.ReadAll(bufr)
checkErr(err, "ReadAll on remainder")
if e, g := "Next Request Here", string(rest); e != g {
g = regexp.MustCompile(`(xx+)`).ReplaceAllStringFunc(g, func(match string) string {
import (
"bytes"
- "io/ioutil"
+ "io"
"strings"
"testing"
)
ProtoMinor: 0,
Request: dummyReq("GET"),
Header: Header{},
- Body: ioutil.NopCloser(strings.NewReader("abcdef")),
+ Body: io.NopCloser(strings.NewReader("abcdef")),
ContentLength: 6,
},
ProtoMinor: 0,
Request: dummyReq("GET"),
Header: Header{},
- Body: ioutil.NopCloser(strings.NewReader("abcdef")),
+ Body: io.NopCloser(strings.NewReader("abcdef")),
ContentLength: -1,
},
"HTTP/1.0 200 OK\r\n" +
ProtoMinor: 1,
Request: dummyReq("GET"),
Header: Header{},
- Body: ioutil.NopCloser(strings.NewReader("abcdef")),
+ Body: io.NopCloser(strings.NewReader("abcdef")),
ContentLength: -1,
Close: true,
},
ProtoMinor: 1,
Request: dummyReq11("GET"),
Header: Header{},
- Body: ioutil.NopCloser(strings.NewReader("abcdef")),
+ Body: io.NopCloser(strings.NewReader("abcdef")),
ContentLength: -1,
Close: false,
},
ProtoMinor: 1,
Request: dummyReq11("GET"),
Header: Header{},
- Body: ioutil.NopCloser(strings.NewReader("abcdef")),
+ Body: io.NopCloser(strings.NewReader("abcdef")),
ContentLength: -1,
TransferEncoding: []string{"chunked"},
Close: false,
ProtoMinor: 1,
Request: dummyReq11("GET"),
Header: Header{},
- Body: ioutil.NopCloser(strings.NewReader("")),
+ Body: io.NopCloser(strings.NewReader("")),
ContentLength: 0,
Close: false,
},
ProtoMinor: 1,
Request: dummyReq11("GET"),
Header: Header{},
- Body: ioutil.NopCloser(strings.NewReader("foo")),
+ Body: io.NopCloser(strings.NewReader("foo")),
ContentLength: 0,
Close: false,
},
ProtoMinor: 1,
Request: dummyReq("GET"),
Header: Header{},
- Body: ioutil.NopCloser(strings.NewReader("abcdef")),
+ Body: io.NopCloser(strings.NewReader("abcdef")),
ContentLength: 6,
TransferEncoding: []string{"chunked"},
Close: true,
Request: &Request{Method: "POST"},
Header: Header{},
ContentLength: -1,
- Body: ioutil.NopCloser(strings.NewReader("abcdef")),
+ Body: io.NopCloser(strings.NewReader("abcdef")),
},
"HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nabcdef",
},
"errors"
"fmt"
"io"
- "io/ioutil"
"strconv"
"syscall/js"
)
// See https://github.com/web-platform-tests/wpt/issues/7693 for WHATWG tests issue.
// See https://developer.mozilla.org/en-US/docs/Web/API/Streams_API for more details on the Streams API
// and browser support.
- body, err := ioutil.ReadAll(req.Body)
+ body, err := io.ReadAll(req.Body)
if err != nil {
req.Body.Close() // RoundTrip must always close the body, including on errors.
return nil, err
"fmt"
"internal/testenv"
"io"
- "io/ioutil"
"log"
"math/rand"
"net"
if err != nil {
continue
}
- slurp, _ := ioutil.ReadAll(res.Body)
+ slurp, _ := io.ReadAll(res.Body)
res.Body.Close()
if !tt.statusOk {
if got, want := res.StatusCode, 404; got != want {
if err != nil {
return fmt.Errorf("http Get #1: %v", err)
}
- got, err := ioutil.ReadAll(r.Body)
+ got, err := io.ReadAll(r.Body)
expected := "req=1"
if string(got) != expected || err != nil {
return fmt.Errorf("Unexpected response for request #1; got %q ,%v; expected %q, nil",
if err != nil {
return fmt.Errorf("http Get #2: %v", err)
}
- got, err = ioutil.ReadAll(r.Body)
+ got, err = io.ReadAll(r.Body)
r.Body.Close()
expected = "req=2"
if string(got) != expected || err != nil {
return fmt.Errorf("long Dial: %v", err)
}
defer conn.Close()
- go io.Copy(ioutil.Discard, conn)
+ go io.Copy(io.Discard, conn)
for i := 0; i < 5; i++ {
_, err := conn.Write([]byte("GET / HTTP/1.1\r\nHost: foo\r\n\r\n"))
if err != nil {
errc <- err
return
}
- _, err = io.Copy(ioutil.Discard, res.Body)
+ _, err = io.Copy(io.Discard, res.Body)
res.Body.Close()
errc <- err
}()
}
// The ReadAll will hang for a failing test.
- got, _ := ioutil.ReadAll(conn)
+ got, _ := io.ReadAll(conn)
expectedSuffix := "\r\n\r\ntoo short"
if !strings.HasSuffix(string(got), expectedSuffix) {
t.Errorf("Expected output to end with %q; got response body %q",
}
}()
- _, err = ioutil.ReadAll(r)
+ _, err = io.ReadAll(r)
if err != nil {
t.Fatal("read error:", err)
}
if err != nil {
t.Fatalf("res %d: %v", i+1, err)
}
- if _, err := io.Copy(ioutil.Discard, res.Body); err != nil {
+ if _, err := io.Copy(io.Discard, res.Body); err != nil {
t.Fatalf("res %d body copy: %v", i+1, err)
}
res.Body.Close()
if err != nil {
t.Fatalf("Get error: %v", err)
}
- body, err := ioutil.ReadAll(res.Body)
+ body, err := io.ReadAll(res.Body)
if err != nil {
t.Fatalf("ReadAll error: %v", err)
}
return
}
defer resp.Body.Close()
- body, err := ioutil.ReadAll(resp.Body)
+ body, err := io.ReadAll(resp.Body)
if err != nil {
t.Errorf("Request %d: %v", num, err)
response <- ""
if v := res.ContentLength; v != 10 {
t.Errorf("Content-Length: %d; want 10", v)
}
- body, err := ioutil.ReadAll(res.Body)
+ body, err := io.ReadAll(res.Body)
if err != nil {
t.Error(err)
}
}
}
}))
- ts.Config.ErrorLog = log.New(ioutil.Discard, "", 0)
+ ts.Config.ErrorLog = log.New(io.Discard, "", 0)
defer ts.Close()
// Connect an idle TCP connection to this server before we run
}
defer conn.Close()
io.WriteString(conn, "GET / HTTP/1.1\r\nHost: foo\r\n\r\n")
- slurp, err := ioutil.ReadAll(conn)
+ slurp, err := io.ReadAll(conn)
if err != nil {
t.Fatal(err)
}
// requests that would read from r.Body, which we only
// conditionally want to do.
if strings.Contains(r.URL.RawQuery, "readbody=true") {
- ioutil.ReadAll(r.Body)
+ io.ReadAll(r.Body)
w.Write([]byte("Hi"))
} else {
w.WriteHeader(StatusUnauthorized)
io.Closer
}{
conn,
- ioutil.NopCloser(nil),
+ io.NopCloser(nil),
}
if test.chunked {
targ = httputil.NewChunkedWriter(conn)
var testHandlerBodyConsumers = []testHandlerBodyConsumer{
{"nil", func(io.ReadCloser) {}},
{"close", func(r io.ReadCloser) { r.Close() }},
- {"discard", func(r io.ReadCloser) { io.Copy(ioutil.Discard, r) }},
+ {"discard", func(r io.ReadCloser) { io.Copy(io.Discard, r) }},
}
func TestRequestBodyReadErrorClosesConnection(t *testing.T) {
if g, e := res.StatusCode, StatusOK; g != e {
t.Errorf("got res.StatusCode %d; expected %d", g, e)
}
- body, _ := ioutil.ReadAll(res.Body)
+ body, _ := io.ReadAll(res.Body)
if g, e := string(body), "hi"; g != e {
t.Errorf("got body %q; expected %q", g, e)
}
if g, e := res.StatusCode, StatusServiceUnavailable; g != e {
t.Errorf("got res.StatusCode %d; expected %d", g, e)
}
- body, _ = ioutil.ReadAll(res.Body)
+ body, _ = io.ReadAll(res.Body)
if !strings.Contains(string(body), "<title>Timeout</title>") {
t.Errorf("expected timeout body; got %q", string(body))
}
defer func() { <-gate }()
res, err := c.Get(fmt.Sprintf("%s/%d", ts.URL, rand.Intn(50)))
if err == nil {
- io.Copy(ioutil.Discard, res.Body)
+ io.Copy(io.Discard, res.Body)
res.Body.Close()
}
}()
return
}
defer res.Body.Close()
- io.Copy(ioutil.Discard, res.Body)
+ io.Copy(io.Discard, res.Body)
}()
}
wg.Wait()
if g, e := res.StatusCode, StatusOK; g != e {
t.Errorf("got res.StatusCode %d; expected %d", g, e)
}
- body, _ := ioutil.ReadAll(res.Body)
+ body, _ := io.ReadAll(res.Body)
if g, e := string(body), "hi"; g != e {
t.Errorf("got body %q; expected %q", g, e)
}
if g, e := res.StatusCode, StatusServiceUnavailable; g != e {
t.Errorf("got res.StatusCode %d; expected %d", g, e)
}
- body, _ = ioutil.ReadAll(res.Body)
+ body, _ = io.ReadAll(res.Body)
if !strings.Contains(string(body), "<title>Timeout</title>") {
t.Errorf("expected timeout body; got %q", string(body))
}
t.Errorf("Redirect(%q, %#v) generated Content-Type header %q; want %q", tt.method, tt.ct, got, want)
}
resp := rec.Result()
- body, err := ioutil.ReadAll(resp.Body)
+ body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
setParallel(t)
defer afterTest(t)
cst := newClientServerTest(t, h2, HandlerFunc(func(rw ResponseWriter, r *Request) {
- all, err := ioutil.ReadAll(r.Body)
+ all, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("handler ReadAll: %v", err)
}
}
for i := range resp {
- all, err := ioutil.ReadAll(resp[i].Body)
+ all, err := io.ReadAll(resp[i].Body)
if err != nil {
t.Fatalf("req #%d: client ReadAll: %v", i, err)
}
func testHandlerPanic(t *testing.T, withHijack, h2 bool, wrapper func(Handler) Handler, panicValue interface{}) {
defer afterTest(t)
- // Unlike the other tests that set the log output to ioutil.Discard
+ // Unlike the other tests that set the log output to io.Discard
// to quiet the output, this test uses a pipe. The pipe serves three
// purposes:
//
const limit = 1 << 20
cst := newClientServerTest(t, h2, HandlerFunc(func(w ResponseWriter, r *Request) {
r.Body = MaxBytesReader(w, r.Body, limit)
- n, err := io.Copy(ioutil.Discard, r.Body)
+ n, err := io.Copy(io.Discard, r.Body)
if err == nil {
t.Errorf("expected error from io.Copy")
}
donec := make(chan bool)
go func() {
defer close(donec)
- bs, err := ioutil.ReadAll(conn)
+ bs, err := io.ReadAll(conn)
if err != nil {
t.Errorf("ReadAll: %v", err)
}
r.Body = nil // to test that server.go doesn't use this value.
gone := w.(CloseNotifier).CloseNotify()
- slurp, err := ioutil.ReadAll(reqBody)
+ slurp, err := io.ReadAll(reqBody)
if err != nil {
t.Errorf("Body read: %v", err)
return
}}}
server := &Server{
Handler: HandlerFunc(HandlerFunc(func(ResponseWriter, *Request) {})),
- ErrorLog: log.New(ioutil.Discard, "", 0), // noisy otherwise
+ ErrorLog: log.New(io.Discard, "", 0), // noisy otherwise
}
err := server.Serve(ln)
if err != io.EOF {
close(done)
}()
time.Sleep(25 * time.Millisecond) // give Copy a chance to break things
- n, err := io.Copy(ioutil.Discard, req.Body)
+ n, err := io.Copy(io.Discard, req.Body)
if err != nil {
t.Errorf("handler Copy: %v", err)
return
if err != nil {
t.Fatal(err)
}
- all, err := ioutil.ReadAll(res.Body)
+ all, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
errorf("Proxy outbound request: %v", err)
return
}
- _, err = io.CopyN(ioutil.Discard, bresp.Body, bodySize/2)
+ _, err = io.CopyN(io.Discard, bresp.Body, bodySize/2)
if err != nil {
errorf("Proxy copy error: %v", err)
return
ts.Close()
}()
- ts.Config.ErrorLog = log.New(ioutil.Discard, "", 0)
+ ts.Config.ErrorLog = log.New(io.Discard, "", 0)
ts.Config.ConnState = func(c net.Conn, state ConnState) {
if c == nil {
t.Errorf("nil conn seen in state %s", state)
t.Errorf("Error fetching %s: %v", url, err)
return
}
- _, err = ioutil.ReadAll(res.Body)
+ _, err = io.ReadAll(res.Body)
defer res.Body.Close()
if err != nil {
t.Errorf("Error reading %s: %v", url, err)
if err != nil {
t.Fatal(err)
}
- if _, err := io.Copy(ioutil.Discard, res.Body); err != nil {
+ if _, err := io.Copy(io.Discard, res.Body); err != nil {
t.Fatal(err)
}
c.Close()
}
}
defer res.Body.Close()
- _, err = io.Copy(ioutil.Discard, res.Body)
+ _, err = io.Copy(io.Discard, res.Body)
if err != nil {
t.Error(err)
return
srv.Serve(&oneConnListener{
conn: &rwTestConn{
Reader: strings.NewReader("GET / HTTP/1.1\r\nHost: foo\r\n\r\n"),
- Writer: ioutil.Discard,
+ Writer: io.Discard,
},
})
if !sawNew { // testing that this read isn't racy
t.Fatal(err)
}
defer res.Body.Close()
- all, err := ioutil.ReadAll(res.Body)
+ all, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
go Serve(ln, HandlerFunc(func(w ResponseWriter, r *Request) {
numReq++
if r.URL.Path == "/readbody" {
- ioutil.ReadAll(r.Body)
+ io.ReadAll(r.Body)
}
io.WriteString(w, "Hello world!")
}))
t.Fatal(err)
}
defer res.Body.Close()
- slurp, err := ioutil.ReadAll(res.Body)
+ slurp, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
}
defer c.Close()
io.WriteString(c, "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n")
- slurp, err := ioutil.ReadAll(c)
+ slurp, err := io.ReadAll(c)
if err != nil {
t.Fatal(err)
}
if err != nil {
b.Fatal("Get:", err)
}
- all, err := ioutil.ReadAll(res.Body)
+ all, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
b.Fatal("ReadAll:", err)
b.Logf("Get: %v", err)
continue
}
- all, err := ioutil.ReadAll(res.Body)
+ all, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
b.Logf("ReadAll: %v", err)
if err != nil {
log.Panicf("Get: %v", err)
}
- all, err := ioutil.ReadAll(res.Body)
+ all, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
log.Panicf("ReadAll: %v", err)
if err != nil {
b.Fatalf("Get: %v", err)
}
- body, err := ioutil.ReadAll(res.Body)
+ body, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
b.Fatalf("ReadAll: %v", err)
conn := &rwTestConn{
Reader: &repeatReader{content: req, count: b.N},
- Writer: ioutil.Discard,
+ Writer: io.Discard,
closec: make(chan bool, 1),
}
handled := 0
conn := &rwTestConn{
Reader: &repeatReader{content: req, count: b.N},
- Writer: ioutil.Discard,
+ Writer: io.Discard,
closec: make(chan bool, 1),
}
handled := 0
`)
conn := &rwTestConn{
Reader: &repeatReader{content: req, count: b.N},
- Writer: ioutil.Discard,
+ Writer: io.Discard,
closec: make(chan bool, 1),
}
handled := 0
conn.Close()
})
conn := &rwTestConn{
- Writer: ioutil.Discard,
+ Writer: io.Discard,
closec: make(chan bool, 1),
}
ln := &oneConnListener{conn: conn}
setParallel(t)
defer afterTest(t)
ts := httptest.NewUnstartedServer(HandlerFunc(func(w ResponseWriter, r *Request) {
- io.Copy(ioutil.Discard, r.Body)
+ io.Copy(io.Discard, r.Body)
io.WriteString(w, r.RemoteAddr)
}))
ts.Config.ReadHeaderTimeout = 1 * time.Second
t.Fatal(err)
}
defer res.Body.Close()
- slurp, err := ioutil.ReadAll(res.Body)
+ slurp, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
defer conn.Close()
conn.Write([]byte("GET / HTTP/1.1\r\nHost: foo.com\r\n"))
time.Sleep(2 * time.Second)
- if _, err := io.CopyN(ioutil.Discard, conn, 1); err == nil {
+ if _, err := io.CopyN(io.Discard, conn, 1); err == nil {
t.Fatal("copy byte succeeded; want err")
}
}
t.Fatal(err)
}
defer res.Body.Close()
- slurp, err := ioutil.ReadAll(res.Body)
+ slurp, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
if err != nil {
return fmt.Errorf("Get: %v", err)
}
- slurp, err := ioutil.ReadAll(res.Body)
+ slurp, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
return fmt.Errorf("Body ReadAll: %v", err)
wg.Add(1)
go func() {
defer wg.Done()
- io.Copy(ioutil.Discard, cn)
+ io.Copy(io.Discard, cn)
}()
for j := 0; j < requests; j++ {
return
}
defer conn.Close()
- slurp, err := ioutil.ReadAll(buf.Reader)
+ slurp, err := io.ReadAll(buf.Reader)
if err != nil {
t.Errorf("Copy: %v", err)
}
if _, err := conn.Write(http1ReqBody); err != nil {
return nil, err
}
- return ioutil.ReadAll(conn)
+ return io.ReadAll(conn)
}
func BenchmarkResponseStatusLine(b *testing.B) {
b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
- bw := bufio.NewWriter(ioutil.Discard)
+ bw := bufio.NewWriter(io.Discard)
var buf3 [3]byte
for pb.Next() {
Export_writeStatusLine(bw, true, 200, buf3[:])
"errors"
"fmt"
"io"
- "io/ioutil"
"log"
"net"
"net/textproto"
}
if discard {
- _, err := io.CopyN(ioutil.Discard, w.reqBody, maxPostHandlerReadBytes+1)
+ _, err := io.CopyN(io.Discard, w.reqBody, maxPostHandlerReadBytes+1)
switch err {
case nil:
// There must be even more data left over.
// (or an attack) and we abort and close the connection,
// courtesy of MaxBytesReader's EOF behavior.
mb := MaxBytesReader(w, r.Body, 4<<10)
- io.Copy(ioutil.Discard, mb)
+ io.Copy(io.Discard, mb)
}
}
"bytes"
"fmt"
"io"
- "io/ioutil"
"log"
. "net/http"
"reflect"
if ct := resp.Header.Get("Content-Type"); ct != wantContentType {
t.Errorf("%v: Content-Type = %q, want %q", tt.desc, ct, wantContentType)
}
- data, err := ioutil.ReadAll(resp.Body)
+ data, err := io.ReadAll(resp.Body)
if err != nil {
t.Errorf("%v: reading body: %v", tt.desc, err)
} else if !bytes.Equal(data, tt.data) {
if ct := resp.Header.Get("Content-Type"); ct != expected {
t.Errorf("Content-Type = %q, want %q", ct, expected)
}
- data, err := ioutil.ReadAll(resp.Body)
+ data, err := io.ReadAll(resp.Body)
if err != nil {
t.Errorf("reading body: %v", err)
} else if !bytes.Equal(data, []byte(input)) {
if err != nil {
t.Fatalf("size %d: %v", size, err)
}
- if _, err := io.Copy(ioutil.Discard, res.Body); err != nil {
+ if _, err := io.Copy(io.Discard, res.Body); err != nil {
t.Fatalf("size %d: io.Copy of body = %v", size, err)
}
if err := res.Body.Close(); err != nil {
"errors"
"fmt"
"io"
- "io/ioutil"
"net/http/httptrace"
"net/http/internal"
"net/textproto"
// servers. See Issue 18257, as one example.
//
// The only reason we'd send such a request is if the user set the Body to a
-// non-nil value (say, ioutil.NopCloser(bytes.NewReader(nil))) and didn't
+// non-nil value (say, io.NopCloser(bytes.NewReader(nil))) and didn't
// set ContentLength, or NewRequest set it to -1 (unknown), so then we assume
// there's bytes to send.
//
return err
}
var nextra int64
- nextra, err = t.doBodyCopy(ioutil.Discard, body)
+ nextra, err = t.doBodyCopy(io.Discard, body)
ncopy += nextra
}
if err != nil {
var n int64
// Consume the body, or, which will also lead to us reading
// the trailer headers after the body, if present.
- n, err = io.CopyN(ioutil.Discard, bodyLocked{b}, maxPostHandlerReadBytes)
+ n, err = io.CopyN(io.Discard, bodyLocked{b}, maxPostHandlerReadBytes)
if err == io.EOF {
err = nil
}
default:
// Fully consume the body, which will also lead to us reading
// the trailer headers after the body, if present.
- _, err = io.Copy(ioutil.Discard, bodyLocked{b})
+ _, err = io.Copy(io.Discard, bodyLocked{b})
}
b.closed = true
return err
return
}
-var nopCloserType = reflect.TypeOf(ioutil.NopCloser(nil))
+var nopCloserType = reflect.TypeOf(io.NopCloser(nil))
// isKnownInMemoryReader reports whether r is a type known to not
// block on Read. Its caller uses this as an optional optimization to
{bytes.NewBuffer(nil), true},
{strings.NewReader(""), true},
- {ioutil.NopCloser(pr), false},
+ {io.NopCloser(pr), false},
- {ioutil.NopCloser(bytes.NewReader(nil)), true},
- {ioutil.NopCloser(bytes.NewBuffer(nil)), true},
- {ioutil.NopCloser(strings.NewReader("")), true},
+ {io.NopCloser(bytes.NewReader(nil)), true},
+ {io.NopCloser(bytes.NewBuffer(nil)), true},
+ {io.NopCloser(strings.NewReader("")), true},
}
for i, tt := range tests {
got := isKnownInMemoryReader(tt.r)
func (w *mockTransferWriter) ReadFrom(r io.Reader) (int64, error) {
w.CalledReader = r
- return io.Copy(ioutil.Discard, r)
+ return io.Copy(io.Discard, r)
}
func (w *mockTransferWriter) Write(p []byte) (int, error) {
w.WriteCalled = true
- return ioutil.Discard.Write(p)
+ return io.Discard.Write(p)
}
func TestTransferWriterWriteBodyReaderTypes(t *testing.T) {
method: "PUT",
bodyFunc: func() (io.Reader, func(), error) {
r, cleanup, err := newFileFunc()
- return ioutil.NopCloser(r), cleanup, err
+ return io.NopCloser(r), cleanup, err
},
contentLength: nBytes,
limitedReader: true,
method: "PUT",
bodyFunc: func() (io.Reader, func(), error) {
r, cleanup, err := newBufferFunc()
- return ioutil.NopCloser(r), cleanup, err
+ return io.NopCloser(r), cleanup, err
},
contentLength: nBytes,
limitedReader: true,
"crypto/tls"
"errors"
"io"
- "io/ioutil"
"net"
"net/http/internal"
"strings"
TLSNextProto: map[string]func(string, *tls.Conn) RoundTripper{
"foo": func(authority string, c *tls.Conn) RoundTripper {
return roundTripFunc(func(r *Request) (*Response, error) {
- n, _ := io.Copy(ioutil.Discard, r.Body)
+ n, _ := io.Copy(io.Discard, r.Body)
if n == 0 {
t.Error("body length is zero")
}
if err != nil {
t.Fatalf("error in disableKeepAlive=%v, req #%d, GET: %v", disableKeepAlive, n, err)
}
- body, err := ioutil.ReadAll(res.Body)
+ body, err := io.ReadAll(res.Body)
if err != nil {
t.Fatalf("error in disableKeepAlive=%v, req #%d, ReadAll: %v", disableKeepAlive, n, err)
}
t.Fatalf("error in connectionClose=%v, req #%d, Do: %v", connectionClose, n, err)
}
defer res.Body.Close()
- body, err := ioutil.ReadAll(res.Body)
+ body, err := io.ReadAll(res.Body)
if err != nil {
t.Fatalf("error in connectionClose=%v, req #%d, ReadAll: %v", connectionClose, n, err)
}
t.Errorf("For connectionClose = %v; handler's X-Saw-Close was %v; want %v",
connectionClose, got, !connectionClose)
}
- body, err := ioutil.ReadAll(res.Body)
+ body, err := io.ReadAll(res.Body)
if err != nil {
t.Fatalf("error in connectionClose=%v, req #%d, ReadAll: %v", connectionClose, n, err)
}
if err != nil {
t.Error(err)
}
- ioutil.ReadAll(resp.Body)
+ io.ReadAll(resp.Body)
keys := tr.IdleConnKeysForTesting()
if e, g := 1, len(keys); e != g {
t.Error(err)
return
}
- if _, err := ioutil.ReadAll(resp.Body); err != nil {
+ if _, err := io.ReadAll(resp.Body); err != nil {
t.Errorf("ReadAll: %v", err)
return
}
if err != nil {
t.Errorf("unexpected error for request %s: %v", reqId, err)
}
- _, err = ioutil.ReadAll(resp.Body)
+ _, err = io.ReadAll(resp.Body)
if err != nil {
t.Errorf("unexpected error for request %s: %v", reqId, err)
}
t.Fatalf("request failed: %v", err)
}
defer resp.Body.Close()
- _, err = ioutil.ReadAll(resp.Body)
+ _, err = io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("read body failed: %v", err)
}
t.Fatalf("%s: %v", name, res.Status)
}
defer res.Body.Close()
- slurp, err := ioutil.ReadAll(res.Body)
+ slurp, err := io.ReadAll(res.Body)
if err != nil {
t.Fatalf("%s: %v", name, err)
}
condFatalf("error in req #%d, GET: %v", n, err)
continue
}
- body, err := ioutil.ReadAll(res.Body)
+ body, err := io.ReadAll(res.Body)
if err != nil {
condFatalf("error in req #%d, ReadAll: %v", n, err)
continue
if e, g := int64(123), res.ContentLength; e != g {
t.Errorf("loop %d: expected res.ContentLength of %v, got %v", i, e, g)
}
- if all, err := ioutil.ReadAll(res.Body); err != nil {
+ if all, err := io.ReadAll(res.Body); err != nil {
t.Errorf("loop %d: Body ReadAll: %v", i, err)
} else if len(all) != 0 {
t.Errorf("Bogus body %q", all)
t.Errorf("%d. gzip NewReader: %v", i, err)
continue
}
- body, err = ioutil.ReadAll(r)
+ body, err = io.ReadAll(r)
res.Body.Close()
} else {
- body, err = ioutil.ReadAll(res.Body)
+ body, err = io.ReadAll(res.Body)
}
if err != nil {
t.Errorf("%d. Error: %q", i, err)
if err != nil {
t.Fatal(err)
}
- body, err := ioutil.ReadAll(res.Body)
+ body, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
switch req.URL.Path {
case "/100":
// This endpoint implicitly responds 100 Continue and reads body.
- if _, err := io.Copy(ioutil.Discard, req.Body); err != nil {
+ if _, err := io.Copy(io.Discard, req.Body); err != nil {
t.Error("Failed to read Body", err)
}
rw.WriteHeader(StatusOK)
if err != nil {
log.Fatal(err)
}
- if _, err := io.CopyN(ioutil.Discard, bufrw, req.ContentLength); err != nil {
+ if _, err := io.CopyN(io.Discard, bufrw, req.ContentLength); err != nil {
t.Error("Failed to read Body", err)
}
bufrw.WriteString("HTTP/1.1 200 OK\r\n\r\n")
if err != nil {
t.Fatal(err)
}
- body, err := ioutil.ReadAll(res.Body)
+ body, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
t.Fatal(err)
}
defer res.Body.Close()
- _, err = ioutil.ReadAll(res.Body)
+ _, err = io.ReadAll(res.Body)
if err == nil {
t.Fatal("Expect an error from reading a body.")
}
t.Fatal(err)
}
defer res.Body.Close()
- bs, err := ioutil.ReadAll(res.Body)
+ bs, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
t.Errorf("Post: %v", err)
return
}
- got, err := ioutil.ReadAll(res.Body)
+ got, err := io.ReadAll(res.Body)
if err != nil {
t.Fatalf("Body ReadAll: %v", err)
}
wg.Done()
continue
}
- all, err := ioutil.ReadAll(res.Body)
+ all, err := io.ReadAll(res.Body)
if err != nil {
t.Errorf("read error on req %s: %v", req, err)
wg.Done()
t.Errorf("Error issuing GET: %v", err)
break
}
- _, err = io.Copy(ioutil.Discard, sres.Body)
+ _, err = io.Copy(io.Discard, sres.Body)
if err == nil {
t.Errorf("Unexpected successful copy")
break
})
mux.HandleFunc("/put", func(w ResponseWriter, r *Request) {
defer r.Body.Close()
- io.Copy(ioutil.Discard, r.Body)
+ io.Copy(io.Discard, r.Body)
})
ts := httptest.NewServer(mux)
timeout := 100 * time.Millisecond
tr.CancelRequest(req)
}()
t0 := time.Now()
- body, err := ioutil.ReadAll(res.Body)
+ body, err := io.ReadAll(res.Body)
d := time.Since(t0)
if err != ExportErrRequestCanceled {
close(ch)
}()
t0 := time.Now()
- body, err := ioutil.ReadAll(res.Body)
+ body, err := io.ReadAll(res.Body)
d := time.Since(t0)
if err != ExportErrRequestCanceled {
Status: "200 OK",
StatusCode: 200,
Header: make(Header),
- Body: ioutil.NopCloser(strings.NewReader("You wanted " + req.URL.String())),
+ Body: io.NopCloser(strings.NewReader("You wanted " + req.URL.String())),
}
return res, nil
}
if err != nil {
t.Fatal(err)
}
- bodyb, err := ioutil.ReadAll(res.Body)
+ bodyb, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
// let the foo response finish so we can use its
// connection for /bar
fooGate <- true
- io.Copy(ioutil.Discard, fooRes.Body)
+ io.Copy(io.Discard, fooRes.Body)
fooRes.Body.Close()
})
t.Error(err)
return
}
- slurp, err := ioutil.ReadAll(req.Body)
+ slurp, err := io.ReadAll(req.Body)
if err != nil {
t.Errorf("Server request body slurp: %v", err)
return
if id, idBack := req.Header.Get("Request-Id"), res.Header.Get("Echo-Request-Id"); id != "" && id != idBack {
t.Errorf("%s: response id %q != request id %q", name, idBack, id)
}
- _, err = ioutil.ReadAll(res.Body)
+ _, err = io.ReadAll(res.Body)
if err != nil {
t.Fatalf("%s: Slurp error: %v", name, err)
}
func TestTransportClosesRequestBody(t *testing.T) {
defer afterTest(t)
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
- io.Copy(ioutil.Discard, r.Body)
+ io.Copy(io.Discard, r.Body)
}))
defer ts.Close()
t.Fatal(err)
}
<-closedc
- slurp, err := ioutil.ReadAll(res.Body)
+ slurp, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
errs = append(errs, err)
continue
}
- slurp, err = ioutil.ReadAll(res.Body)
+ slurp, err = io.ReadAll(res.Body)
if err != nil {
errs = append(errs, err)
continue
sconn.c = conn
sconn.Unlock()
conn.Write([]byte("HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nfoo")) // keep-alive
- go io.Copy(ioutil.Discard, conn)
+ go io.Copy(io.Discard, conn)
}))
defer ts.Close()
c := ts.Client()
defer afterTest(t)
readBody := make(chan error, 1)
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
- _, err := ioutil.ReadAll(r.Body)
+ _, err := io.ReadAll(r.Body)
readBody <- err
}))
defer ts.Close()
// If we do an early close, Transport just throws the connection away and
// doesn't reuse it. In order to trigger the bug, it has to reuse the connection
// so read the body
- if _, err := io.Copy(ioutil.Discard, res.Body); err != nil {
+ if _, err := io.Copy(io.Discard, res.Body); err != nil {
t.Fatal(err)
}
t.Fatal(err)
}
- body, err := ioutil.ReadAll(res.Body)
+ body, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
t.Fatal(err)
if err != nil {
t.Fatal(err)
}
- io.Copy(ioutil.Discard, req.Body)
+ io.Copy(io.Discard, req.Body)
// Unblock the transport's roundTrip goroutine.
resBody <- strings.NewReader("HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n")
// Do nothing for the second request.
return
}
- if _, err := ioutil.ReadAll(r.Body); err != nil {
+ if _, err := io.ReadAll(r.Body); err != nil {
t.Error(err)
}
if !noHooks {
t.Fatal(err)
}
logf("got roundtrip.response")
- slurp, err := ioutil.ReadAll(res.Body)
+ slurp, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
if err != nil {
return err
}
- slurp, err := ioutil.ReadAll(res.Body)
+ slurp, err := io.ReadAll(res.Body)
if err != nil {
return fmt.Errorf("error reading body: %v", err)
}
conn, _ := ln.Accept()
if conn != nil {
io.WriteString(conn, raw)
- ioutil.ReadAll(conn)
+ io.ReadAll(conn)
conn.Close()
}
}()
t.Error("panicked, expecting an error")
}
if res != nil && res.Body != nil {
- io.Copy(ioutil.Discard, res.Body)
+ io.Copy(io.Discard, res.Body)
res.Body.Close()
}
}
close(cancel)
- got, err := ioutil.ReadAll(res.Body)
+ got, err := io.ReadAll(res.Body)
if err == nil {
t.Fatalf("unexpected success; read %q, nil", got)
}
}
func TestTransportRequestReplayable(t *testing.T) {
- someBody := ioutil.NopCloser(strings.NewReader(""))
+ someBody := io.NopCloser(strings.NewReader(""))
tests := []struct {
name string
req *Request
t,
h1Mode,
HandlerFunc(func(w ResponseWriter, r *Request) {
- io.Copy(ioutil.Discard, r.Body)
+ io.Copy(io.Discard, r.Body)
r.Body.Close()
w.WriteHeader(200)
}),
if err != nil {
t.Fatal(err)
}
- slurp, err := ioutil.ReadAll(res.Body)
+ slurp, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
return
}
defer resp.Body.Close()
- _, err = ioutil.ReadAll(resp.Body)
+ _, err = io.ReadAll(resp.Body)
if err != nil {
errCh <- fmt.Errorf("read body failed: %v", err)
}
func TestIssue32441(t *testing.T) {
defer afterTest(t)
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
- if n, _ := io.Copy(ioutil.Discard, r.Body); n == 0 {
+ if n, _ := io.Copy(io.Discard, r.Body); n == 0 {
t.Error("body length is zero")
}
}))
c := ts.Client()
c.Transport.(*Transport).RegisterProtocol("http", roundTripFunc(func(r *Request) (*Response, error) {
// Draining body to trigger failure condition on actual request to server.
- if n, _ := io.Copy(ioutil.Discard, r.Body); n == 0 {
+ if n, _ := io.Copy(io.Discard, r.Body); n == 0 {
t.Error("body length is zero during round trip")
}
return nil, ErrSkipAltProtocol
if err == nil {
// Ensure all the body is read; otherwise
// we'll get a partial dump.
- io.Copy(ioutil.Discard, req.Body)
+ io.Copy(io.Discard, req.Body)
req.Body.Close()
}
select {
import (
"fmt"
- "io/ioutil"
+ "io"
"log"
"net/mail"
"strings"
fmt.Println("To:", header.Get("To"))
fmt.Println("Subject:", header.Get("Subject"))
- body, err := ioutil.ReadAll(m.Body)
+ body, err := io.ReadAll(m.Body)
if err != nil {
log.Fatal(err)
}
import (
"bytes"
"io"
- "io/ioutil"
"mime"
"reflect"
"strings"
t.Errorf("test #%d: Incorrectly parsed message header.\nGot:\n%+v\nWant:\n%+v",
i, msg.Header, test.header)
}
- body, err := ioutil.ReadAll(msg.Body)
+ body, err := io.ReadAll(msg.Body)
if err != nil {
t.Errorf("test #%d: Failed reading body: %v", i, err)
continue
ap := AddressParser{WordDecoder: &mime.WordDecoder{
CharsetReader: func(charset string, input io.Reader) (io.Reader, error) {
- in, err := ioutil.ReadAll(input)
+ in, err := io.ReadAll(input)
if err != nil {
return nil, err
}
"errors"
"fmt"
"io"
- "io/ioutil"
"net"
"net/rpc"
"reflect"
func TestMalformedOutput(t *testing.T) {
cli, srv := net.Pipe()
go srv.Write([]byte(`{"id":0,"result":null,"error":null}`))
- go ioutil.ReadAll(srv)
+ go io.ReadAll(srv)
client := NewClient(cli)
defer client.Close()
}{
Reader: strings.NewReader(`{"method": "Arith.Add", "id": "123", "params": []}`),
Writer: &out,
- Closer: ioutil.NopCloser(nil),
+ Closer: io.NopCloser(nil),
})
r := new(rpc.Request)
if err := sc.ReadRequestHeader(r); err != nil {
"encoding/hex"
"fmt"
"io"
- "io/ioutil"
"os"
"runtime"
"sync"
return
}
defer conn.Close()
- io.Copy(ioutil.Discard, conn)
+ io.Copy(io.Discard, conn)
}()
// Wait for the byte to be copied, meaning that sendfile has
import (
"io"
- "io/ioutil"
"log"
"os"
"os/exec"
}
defer fromProxy.Close()
- _, err = ioutil.ReadAll(fromProxy)
+ _, err = io.ReadAll(fromProxy)
if err != nil {
t.Fatal(err)
}
"bytes"
"fmt"
"io"
- "io/ioutil"
"strconv"
"strings"
"sync"
//
// See the documentation for the DotReader method for details about dot-encoding.
func (r *Reader) ReadDotBytes() ([]byte, error) {
- return ioutil.ReadAll(r.DotReader())
+ return io.ReadAll(r.DotReader())
}
// ReadDotLines reads a dot-encoding and returns a slice
"fmt"
"internal/testenv"
"io"
- "io/ioutil"
"net/internal/socktest"
"os"
"runtime"
if err := c.SetDeadline(t0.Add(timeout)); err != nil {
t.Error(err)
}
- n, err := io.Copy(ioutil.Discard, c)
+ n, err := io.Copy(io.Discard, c)
dt := time.Since(t0)
c.Close()
ch <- result{n, err, dt}
"fmt"
"internal/poll"
"io"
- "io/ioutil"
"reflect"
"runtime"
"sync"
[]byte("in "),
[]byte("Gopherland ... "),
}
- got, err := ioutil.ReadAll(&buffers)
+ got, err := io.ReadAll(&buffers)
if err != nil {
t.Fatal(err)
}
}
return nil
}, func(c *TCPConn) error {
- all, err := ioutil.ReadAll(c)
+ all, err := io.ReadAll(c)
if !bytes.Equal(all, want.Bytes()) || err != nil {
return fmt.Errorf("client read %q, %v; want %q, nil", all, err, want.Bytes())
}
"encoding/json"
"fmt"
"io"
- "io/ioutil"
"log"
"os"
"os/exec"
log.Fatal(err)
}
- slurp, _ := ioutil.ReadAll(stderr)
+ slurp, _ := io.ReadAll(stderr)
fmt.Printf("%s\n", slurp)
if err := cmd.Wait(); err != nil {
// cgo), to make sure none of that potential C code leaks fds.
ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
// quiet expected TLS handshake error "remote error: bad certificate"
- ts.Config.ErrorLog = log.New(ioutil.Discard, "", 0)
+ ts.Config.ErrorLog = log.New(io.Discard, "", 0)
ts.StartTLS()
defer ts.Close()
_, err = http.Get(ts.URL)
}
}
case "stdinClose":
- b, err := ioutil.ReadAll(os.Stdin)
+ b, err := io.ReadAll(os.Stdin)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
import (
"fmt"
"internal/poll"
- "io/ioutil"
+ "io"
"os"
"os/exec"
"runtime"
func main() {
fd3 := os.NewFile(3, "fd3")
- bs, err := ioutil.ReadAll(fd3)
+ bs, err := io.ReadAll(fd3)
if err != nil {
fmt.Printf("ReadAll from fd 3: %v\n", err)
os.Exit(1)
if err := r.SetDeadline(t0.Add(timeout)); err != nil {
t.Error(err)
}
- n, err := io.Copy(ioutil.Discard, r)
+ n, err := io.Copy(io.Discard, r)
dt := time.Since(t0)
r.Close()
actvch <- result{n, err, dt}
var wg sync.WaitGroup
defer wg.Wait()
- go io.Copy(ioutil.Discard, r)
+ go io.Copy(io.Discard, r)
w.SetWriteDeadline(time.Now().Add(time.Millisecond))
for i := 0; i < 10; i++ {
}
// Get traceback.
- tb, err := ioutil.ReadAll(pr)
+ tb, err := io.ReadAll(pr)
if err != nil {
t.Fatal("reading traceback from pipe: ", err)
}
"errors"
"fmt"
"io"
- "io/ioutil"
"log"
"net"
"os"
// Block blocks until stdin is closed.
func Block() {
- io.Copy(ioutil.Discard, os.Stdin)
+ io.Copy(io.Discard, os.Stdin)
}
"bytes"
"fmt"
"io"
- "io/ioutil"
"strings"
"sync"
"testing"
// tests that Len is affected by reads, but Size is not.
func TestReaderLenSize(t *testing.T) {
r := strings.NewReader("abc")
- io.CopyN(ioutil.Discard, r, 1)
+ io.CopyN(io.Discard, r, 1)
if r.Len() != 2 {
t.Errorf("Len = %d; want 2", r.Len())
}
if err := r.UnreadRune(); err == nil {
t.Errorf("UnreadRune: expected error, got nil")
}
- buf, err := ioutil.ReadAll(r)
+ buf, err := io.ReadAll(r)
if err != nil {
t.Errorf("ReadAll: unexpected error: %v", err)
}
t.Errorf("UnreadRune: got nil, want error")
}
- if n, err := (&strings.Reader{}).WriteTo(ioutil.Discard); n != 0 || err != nil {
+ if n, err := (&strings.Reader{}).WriteTo(io.Discard); n != 0 || err != nil {
t.Errorf("WriteTo: got %d, %v; want 0, nil", n, err)
}
}
import (
"fmt"
"go/format"
- "io/ioutil"
+ "io"
"log"
"os"
"regexp"
)
func main() {
- b, err := ioutil.ReadAll(os.Stdin)
+ b, err := io.ReadAll(os.Stdin)
if err != nil {
log.Fatal(err)
}
f := os.NewFile(uintptr(gotFds[0]), "fd-from-child")
defer f.Close()
- got, err := ioutil.ReadAll(f)
+ got, err := io.ReadAll(f)
want := "Hello from child process!\n"
if string(got) != want {
t.Errorf("child process ReadAll: %q, %v; want %q", got, err, want)
"errors"
"fmt"
"io"
- "io/ioutil"
)
// OneByteReader returns a Reader that implements
}
}
- data, err := ioutil.ReadAll(&smallByteReader{r: r})
+ data, err := io.ReadAll(&smallByteReader{r: r})
if err != nil {
return err
}
}
// Reading forward should return the last part of the file.
- data, err := ioutil.ReadAll(&smallByteReader{r: r})
+ data, err := io.ReadAll(&smallByteReader{r: r})
if err != nil {
return fmt.Errorf("ReadAll from offset %d: %v", middle, err)
}
}
// Reading forward should return the last part of the file (again).
- data, err = ioutil.ReadAll(&smallByteReader{r: r})
+ data, err = io.ReadAll(&smallByteReader{r: r})
if err != nil {
return fmt.Errorf("ReadAll from offset %d: %v", middle, err)
}
if off, err := r.Seek(int64(middle/2), 0); off != int64(middle/2) || err != nil {
return fmt.Errorf("Seek(%d, 0) from EOF = %d, %v, want %d, nil", middle/2, off, err, middle/2)
}
- data, err = ioutil.ReadAll(r)
+ data, err = io.ReadAll(r)
if err != nil {
return fmt.Errorf("ReadAll from offset %d: %v", middle/2, err)
}
"bytes"
"fmt"
"io"
- "io/ioutil"
"testing"
. "text/tabwriter"
)
b.Run("new", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
- w := NewWriter(ioutil.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings
+ w := NewWriter(io.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings
// Write the line h times.
for j := 0; j < h; j++ {
w.Write(line)
b.Run("reuse", func(b *testing.B) {
b.ReportAllocs()
- w := NewWriter(ioutil.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings
+ w := NewWriter(io.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings
for i := 0; i < b.N; i++ {
// Write the line h times.
for j := 0; j < h; j++ {
b.Run(fmt.Sprintf("%d", x), func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
- w := NewWriter(ioutil.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings
+ w := NewWriter(io.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings
// Write increasing prefixes of that line.
for j := 0; j < x; j++ {
w.Write(line[:j*2])
b.Run(fmt.Sprintf("%d", h), func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
- w := NewWriter(ioutil.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings
+ w := NewWriter(io.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings
// Write the lines in turn h times.
for j := 0; j < h; j++ {
w.Write(lines[j%len(lines)])
func BenchmarkCode(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
- w := NewWriter(ioutil.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings
+ w := NewWriter(io.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings
// The code is small, so it's reasonable for the tabwriter user
// to write it all at once, or buffer the writes.
w.Write([]byte(codeSnippet))
"errors"
"flag"
"fmt"
- "io/ioutil"
+ "io"
"reflect"
"strings"
"testing"
if err != nil {
t.Fatal(err)
}
- err = tmpl.Execute(ioutil.Discard, 0)
+ err = tmpl.Execute(io.Discard, 0)
if err == nil {
t.Fatal("expected error; got none")
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
tmpl := Must(New("tmpl").Parse(tc.src))
- err := tmpl.Execute(ioutil.Discard, tc.value)
+ err := tmpl.Execute(io.Discard, tc.value)
got := "<nil>"
if err != nil {
got = err.Error()
t.Skip("skipping in -short mode")
}
tmpl := Must(New("tmpl").Parse(`{{template "tmpl" .}}`))
- err := tmpl.Execute(ioutil.Discard, nil)
+ err := tmpl.Execute(io.Discard, nil)
got := "<nil>"
if err != nil {
got = err.Error()
"encoding/xml"
"flag"
"go/format"
+ "io"
"io/ioutil"
"log"
"net/http"
}
defer r.Body.Close()
- data, err := ioutil.ReadAll(r.Body)
+ data, err := io.ReadAll(r.Body)
if err != nil {
return nil, err
}