Do not tolerate single LF in chunked ending.

As this is not suggested in the spec.
This commit is contained in:
Chen Yufei
2013-02-21 10:02:56 +08:00
parent 8c6f9a639c
commit 8d5e2c7800
2 changed files with 10 additions and 11 deletions

View File

@@ -968,7 +968,10 @@ func sendBodyChunked(buf []byte, r *bufio.Reader, w io.Writer) (err error) {
}
return
}
total := len(s) + int(size) // total data size for this chunk, not including ending CRLF
// The spec section 19.3 only suggest toleranting single LF for
// headers, so assume the server will send CRLF. If not, the following
// parse int may find errors.
total := len(s) + int(size) + 2 // total data size for this chunk, including ending CRLF
bn := r.Buffered()
left := total - bn
if left < 0 { // buffered content has more data than the current chunk
@@ -987,13 +990,7 @@ func sendBodyChunked(buf []byte, r *bufio.Reader, w io.Writer) (err error) {
debug.Println("Copying chunked data:", err)
return
}
} else {
if _, err = w.Write([]byte(CRLF)); err != nil {
debug.Println("Writing chunk ending CRLF:", err)
return
}
}
skipCRLF(r)
}
return
}

View File

@@ -13,11 +13,13 @@ func TestSendBodyChunked(t *testing.T) {
want string // empty means same as raw
}{
{"1a; ignore-stuff-here\r\nabcdefghijklmnopqrstuvwxyz\r\n10\r\n1234567890abcdef\r\n0\r\n\r\n", ""},
{"1a; ignore-stuff-here\nabcdefghijklmnopqrstuvwxyz\r\n10\n1234567890abcdef\n0\n\n",
// COW will only sanitize CRLF at chunk ending
"1a; ignore-stuff-here\nabcdefghijklmnopqrstuvwxyz\r\n10\n1234567890abcdef\r\n0\r\n\r\n"},
{"0\r\n\r\n", ""},
{"0\n\r\n", "0\r\n\r\n"}, // test for buggy web servers
/*
{"0\n\r\n", "0\r\n\r\n"}, // test for buggy web servers
{"1a; ignore-stuff-here\nabcdefghijklmnopqrstuvwxyz\r\n10\n1234567890abcdef\n0\n\n",
// COW will only sanitize CRLF at chunk ending
"1a; ignore-stuff-here\nabcdefghijklmnopqrstuvwxyz\r\n10\n1234567890abcdef\r\n0\r\n\r\n"},
*/
}
buf := make([]byte, bufSize)