diff options
author | Russ Cox <rsc@golang.org> | 2011-05-03 01:15:41 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2011-05-03 01:15:41 -0400 |
commit | b69a3207814553600c5bcb12e11cc44a2c767e52 (patch) | |
tree | 2bbd7c9ae1b7cb583bf2428c9fc52257c2d2db6b | |
parent | ed54b19716f19a510f1230ab608cacb415b75f7a (diff) | |
download | go-b69a3207814553600c5bcb12e11cc44a2c767e52.tar.gz go-b69a3207814553600c5bcb12e11cc44a2c767e52.zip |
[release-branch.r57] http: new error for reading a body after it's been closed
««« CL 4433094 / e30213b07276
http: new error for reading a body after it's been closed
R=adg
CC=golang-dev
https://golang.org/cl/4433094
»»»
R=adg
CC=golang-dev
https://golang.org/cl/4433098
-rw-r--r-- | src/pkg/http/transfer.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/pkg/http/transfer.go b/src/pkg/http/transfer.go index 98c32bab64..5d32aabbfa 100644 --- a/src/pkg/http/transfer.go +++ b/src/pkg/http/transfer.go @@ -439,9 +439,29 @@ type body struct { hdr interface{} // non-nil (Response or Request) value means read trailer r *bufio.Reader // underlying wire-format reader for the trailer closing bool // is the connection to be closed after reading body? + closed bool +} + +// ErrBodyReadAferClose is returned when reading a Request Body after +// the body has been closed. This typically happens when the body is +// read after an HTTP Handler calls WriteHeader or Write on its +// ResponseWriter. +var ErrBodyReadAferClose = os.NewError("http: invalid Read on closed request Body") + +func (b *body) Read(p []byte) (n int, err os.Error) { + if b.closed { + return 0, ErrBodyReadAferClose + } + return b.Reader.Read(p) } func (b *body) Close() os.Error { + if b.closed { + return nil + } + defer func() { + b.closed = true + }() if b.hdr == nil && b.closing { // no trailer and closing the connection next. // no point in reading to EOF. |