mirror of
https://github.com/golang/go
synced 2024-11-19 14:24:47 -07:00
http: make NewChunkedReader public
R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/4634112
This commit is contained in:
parent
45f956ab82
commit
7983ab9d1a
@ -9,6 +9,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"bufio"
|
||||
)
|
||||
|
||||
// NewChunkedWriter returns a new writer that translates writes into HTTP
|
||||
@ -64,3 +65,13 @@ func (cw *chunkedWriter) Close() os.Error {
|
||||
_, err := io.WriteString(cw.Wire, "0\r\n")
|
||||
return err
|
||||
}
|
||||
|
||||
// NewChunkedReader returns a new reader that translates the data read from r
|
||||
// out of HTTP "chunked" format before returning it.
|
||||
// The reader returns os.EOF when the final 0-length chunk is read.
|
||||
//
|
||||
// NewChunkedReader is not needed by normal applications. The http package
|
||||
// automatically decodes chunking when reading response bodies.
|
||||
func NewChunkedReader(r *bufio.Reader) io.Reader {
|
||||
return &chunkedReader{r: r}
|
||||
}
|
||||
|
@ -428,10 +428,6 @@ type chunkedReader struct {
|
||||
err os.Error
|
||||
}
|
||||
|
||||
func newChunkedReader(r *bufio.Reader) *chunkedReader {
|
||||
return &chunkedReader{r: r}
|
||||
}
|
||||
|
||||
func (cr *chunkedReader) beginChunk() {
|
||||
// chunk-size CRLF
|
||||
var line string
|
||||
|
@ -279,7 +279,7 @@ func readTransfer(msg interface{}, r *bufio.Reader) (err os.Error) {
|
||||
// or close connection when finished, since multipart is not supported yet
|
||||
switch {
|
||||
case chunked(t.TransferEncoding):
|
||||
t.Body = &body{Reader: newChunkedReader(r), hdr: msg, r: r, closing: t.Close}
|
||||
t.Body = &body{Reader: NewChunkedReader(r), hdr: msg, r: r, closing: t.Close}
|
||||
case t.ContentLength >= 0:
|
||||
// TODO: limit the Content-Length. This is an easy DoS vector.
|
||||
t.Body = &body{Reader: io.LimitReader(r, t.ContentLength), closing: t.Close}
|
||||
|
Loading…
Reference in New Issue
Block a user