mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
http/transferWriter: Write body when content length unknown
Fixes #923. R=adg, rsc CC=golang-dev https://golang.org/cl/1846043
This commit is contained in:
parent
2d6ae385e1
commit
18d8c7dac6
2 changed files with 17 additions and 0 deletions
|
|
@ -31,6 +31,21 @@ var respWriteTests = []respWriteTest{
|
||||||
"Content-Length: 6\r\n\r\n" +
|
"Content-Length: 6\r\n\r\n" +
|
||||||
"abcdef",
|
"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
|
// HTTP/1.1, chunked coding; empty trailer; close
|
||||||
respWriteTest{
|
respWriteTest{
|
||||||
Response{
|
Response{
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,8 @@ func (t *transferWriter) WriteBody(w io.Writer) (err os.Error) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = cw.Close()
|
err = cw.Close()
|
||||||
}
|
}
|
||||||
|
} else if t.ContentLength == -1 {
|
||||||
|
_, err = io.Copy(w, t.Body)
|
||||||
} else {
|
} else {
|
||||||
_, err = io.Copy(w, io.LimitReader(t.Body, t.ContentLength))
|
_, err = io.Copy(w, io.LimitReader(t.Body, t.ContentLength))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue