aboutsummaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2015-01-02 10:02:15 -0800
committerBrad Fitzpatrick <bradfitz@golang.org>2015-01-07 06:37:57 +0000
commitee2ecc4552d8fd2b29be29aed1fe81dca0df60f9 (patch)
tree1300cd6fabb2c8a89ef8ad554e40e567d8a3835e /src/net
parent5f179c7cef24c74627632ca1b9df8d5ea3912ace (diff)
downloadgo-ee2ecc4552d8fd2b29be29aed1fe81dca0df60f9.tar.xz
bufio: add Reader.Discard
Reader.Discard is the complement to Peek. It discards the next n bytes of input. We already have Reader.Buffered to see how many bytes of data are sitting available in memory, and Reader.Peek to get that that buffer directly. But once you're done with the Peek'd data, you can't get rid of it, other than Reading it. Both Read and io.CopyN(ioutil.Discard, bufReader, N) are relatively slow. People instead resort to multiple blind ReadByte calls, just to advance the internal b.r variable. I've wanted this previously, several people have asked for it in the past on golang-nuts/dev, and somebody just asked me for it again in a private email. There are a few places in the standard library we'd use it too. Change-Id: I85dfad47704a58bd42f6867adbc9e4e1792bc3b0 Reviewed-on: https://go-review.googlesource.com/2260 Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/net')
-rw-r--r--src/net/http/transfer.go3
1 files changed, 1 insertions, 2 deletions
diff --git a/src/net/http/transfer.go b/src/net/http/transfer.go
index fd9389adf0..c39d6cff67 100644
--- a/src/net/http/transfer.go
+++ b/src/net/http/transfer.go
@@ -638,8 +638,7 @@ func (b *body) readTrailer() error {
// The common case, since nobody uses trailers.
buf, err := b.r.Peek(2)
if bytes.Equal(buf, singleCRLF) {
- b.r.ReadByte()
- b.r.ReadByte()
+ b.r.Discard(2)
return nil
}
if len(buf) < 2 {