Commit 7983ab9d authored by Andrew Balholm's avatar Andrew Balholm Committed by Brad Fitzpatrick

http: make NewChunkedReader public

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/4634112
parent 45f956ab
......@@ -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}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment