]> Cypherpunks repositories - gostls13.git/commitdiff
http/transferWriter: Write body when content length unknown
authorJames Whitehead <jnwhiteh@gmail.com>
Mon, 19 Jul 2010 04:05:27 +0000 (14:05 +1000)
committerAndrew Gerrand <adg@golang.org>
Mon, 19 Jul 2010 04:05:27 +0000 (14:05 +1000)
Fixes #923.

R=adg, rsc
CC=golang-dev
https://golang.org/cl/1846043

src/pkg/http/responsewrite_test.go
src/pkg/http/transfer.go

index 7680643032289a077ac9ca177b557d232d820b2d..ba9ad4bebb400f55b890e26be9e02e4f25450ec0 100644 (file)
@@ -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{
index 5e190d74c6c6d1678291a55ef54a182e076cbd11..50c1b869783564841cc82d0f500cd33cb0009f66 100644 (file)
@@ -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))
                }