From eb5eea9a8f336355fa2c7d006a56bb740b3486ec Mon Sep 17 00:00:00 2001 From: Stephen Ma Date: Mon, 27 Apr 2009 00:38:04 -0700 Subject: [PATCH] Fix the chunked encoding - terminate the chunk with CRLF. R=rsc APPROVED=r DELTA=11 (10 added, 0 deleted, 1 changed) OCL=27723 CL=27879 --- src/lib/http/server.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lib/http/server.go b/src/lib/http/server.go index 3595a515dcb..9b6aa6c414a 100644 --- a/src/lib/http/server.go +++ b/src/lib/http/server.go @@ -174,7 +174,17 @@ func (c *Conn) Write(data []byte) (n int, err os.Error) { if c.chunking { fmt.Fprintf(c.buf, "%x\r\n", len(data)); // TODO(rsc): use strconv not fmt } - return c.buf.Write(data); + n, err = c.buf.Write(data); + if err == nil && c.chunking { + if n != len(data) { + err = bufio.ShortWrite; + } + if err == nil { + io.WriteString(c.buf, "\r\n"); + } + } + + return n, err; } func (c *Conn) flush() {