mirror of
https://github.com/zhigang1992/cow.git
synced 2026-01-12 22:46:29 +08:00
Do not tolerate single LF in chunked ending.
As this is not suggested in the spec.
This commit is contained in:
11
proxy.go
11
proxy.go
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user