diff options
Diffstat (limited to 'src/net/http/http.go')
| -rw-r--r-- | src/net/http/http.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/net/http/http.go b/src/net/http/http.go index 7e0b77506b..40018453c6 100644 --- a/src/net/http/http.go +++ b/src/net/http/http.go @@ -5,6 +5,7 @@ package http import ( + "io" "strconv" "strings" "time" @@ -81,3 +82,21 @@ func hexEscapeNonASCII(s string) string { } return string(b) } + +// NoBody is an io.ReadCloser with no bytes. Read always returns EOF +// and Close always returns nil. It can be used in an outgoing client +// request to explicitly signal that a request has zero bytes. +// An alternative, however, is to simply set Request.Body to nil. +var NoBody = noBody{} + +type noBody struct{} + +func (noBody) Read([]byte) (int, error) { return 0, io.EOF } +func (noBody) Close() error { return nil } +func (noBody) WriteTo(io.Writer) (int64, error) { return 0, nil } + +var ( + // verify that an io.Copy from NoBody won't require a buffer: + _ io.WriterTo = NoBody + _ io.ReadCloser = NoBody +) |
