1
0
mirror of https://github.com/golang/go synced 2024-11-21 21:44:40 -07:00

http: MaxBytesReader doc cleanups

Comments from rsc after 4921049 was submitted.

R=rsc
CC=golang-dev
https://golang.org/cl/5034042
This commit is contained in:
Brad Fitzpatrick 2011-09-15 14:26:22 -07:00
parent 758b62bf6a
commit e30b9fd87e

View File

@ -610,14 +610,14 @@ func ReadRequest(b *bufio.Reader) (req *Request, err os.Error) {
return req, nil return req, nil
} }
// MaxBytesReader is similar to io.LimitReader, but is intended for // MaxBytesReader is similar to io.LimitReader but is intended for
// limiting the size of incoming request bodies. In contrast to // limiting the size of incoming request bodies. In contrast to
// io.LimitReader, MaxBytesReader is a ReadCloser, returns a non-EOF // io.LimitReader, MaxBytesReader's result is a ReadCloser, returns a
// error if the body is too large, and also takes care of closing the // non-EOF error for a Read beyond the limit, and Closes the
// underlying io.ReadCloser connection (if applicable, usually a TCP // underlying reader when its Close method is called.
// connection) when the limit is hit. This prevents clients from //
// accidentally or maliciously sending a large request and wasting // MaxBytesReader prevents clients from accidentally or maliciously
// server resources. // sending a large request and wasting server resources.
func MaxBytesReader(w ResponseWriter, r io.ReadCloser, n int64) io.ReadCloser { func MaxBytesReader(w ResponseWriter, r io.ReadCloser, n int64) io.ReadCloser {
return &maxBytesReader{w: w, r: r, n: n} return &maxBytesReader{w: w, r: r, n: n}
} }
@ -675,7 +675,7 @@ func (r *Request) ParseForm() (err os.Error) {
switch { switch {
case ct == "text/plain" || ct == "application/x-www-form-urlencoded" || ct == "": case ct == "text/plain" || ct == "application/x-www-form-urlencoded" || ct == "":
var reader io.Reader = r.Body var reader io.Reader = r.Body
maxFormSize := int64((1 << 63) - 1) maxFormSize := int64(1<<63 - 1)
if _, ok := r.Body.(*maxBytesReader); !ok { if _, ok := r.Body.(*maxBytesReader); !ok {
maxFormSize = int64(10 << 20) // 10 MB is a lot of text. maxFormSize = int64(10 << 20) // 10 MB is a lot of text.
reader = io.LimitReader(r.Body, maxFormSize+1) reader = io.LimitReader(r.Body, maxFormSize+1)