File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,10 @@ fn parse_request(mut reader io.BufferedReader) ?http.Request {
3636 n := length.int ()
3737 if n > 0 {
3838 body = []byte {len: n}
39- reader.read (mut body) or {}
39+ mut count := 0
40+ for count < body.len {
41+ count + = reader.read (mut body[count..]) or { break }
42+ }
4043 }
4144 }
4245 h.free ()
Original file line number Diff line number Diff line change @@ -12,7 +12,9 @@ fn (mut s StringReader) read(mut buf []byte) ?int {
1212 if s.place > = s.text.len {
1313 return none
1414 }
15- n := copy (buf, s.text[s.place..].bytes ())
15+ max_bytes := 100
16+ end := if s.place + max_bytes > = s.text.len { s.text.len } else { s.place + max_bytes }
17+ n := copy (buf, s.text[s.place..end].bytes ())
1618 s.place + = n
1719 return n
1820}
@@ -135,3 +137,11 @@ ${contents[1]}
135137 names[1 ]: contents[1 ] + '\n '
136138 }
137139}
140+
141+ fn test_parse_large_body () ? {
142+ body := 'A' .repeat (101 ) // greater than max_bytes
143+ req := 'GET / HTTP/1.1\r\n Content-Length: $body.len \r\n\r\n $body '
144+ result := parse_request (mut reader (req)) ?
145+ assert result.data.len == body.len
146+ assert result.data == body
147+ }
You can’t perform that action at this time.
0 commit comments