Commit 18d8c7da authored by James Whitehead's avatar James Whitehead Committed by Andrew Gerrand

http/transferWriter: Write body when content length unknown

Fixes #923.

R=adg, rsc
CC=golang-dev
https://golang.org/cl/1846043
parent 2d6ae385
......@@ -31,6 +31,21 @@ var respWriteTests = []respWriteTest{
"Content-Length: 6\r\n\r\n" +
"abcdef",
},
// Unchunked response without Content-Length.
respWriteTest{
Response{
StatusCode: 200,
ProtoMajor: 1,
ProtoMinor: 0,
RequestMethod: "GET",
Header: map[string]string{},
Body: nopCloser{bytes.NewBufferString("abcdef")},
ContentLength: -1,
},
"HTTP/1.0 200 OK\r\n" +
"\r\n" +
"abcdef",
},
// HTTP/1.1, chunked coding; empty trailer; close
respWriteTest{
Response{
......
......@@ -135,6 +135,8 @@ func (t *transferWriter) WriteBody(w io.Writer) (err os.Error) {
if err == nil {
err = cw.Close()
}
} else if t.ContentLength == -1 {
_, err = io.Copy(w, t.Body)
} else {
_, err = io.Copy(w, io.LimitReader(t.Body, t.ContentLength))
}
......
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