vweb: read the entire request body from buffered reader (#9644)
parent
e93a52a267
commit
67ec33218e
|
@ -36,7 +36,10 @@ fn parse_request(mut reader io.BufferedReader) ?http.Request {
|
||||||
n := length.int()
|
n := length.int()
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
body = []byte{len: n}
|
body = []byte{len: n}
|
||||||
reader.read(mut body) or {}
|
mut count := 0
|
||||||
|
for count < body.len {
|
||||||
|
count += reader.read(mut body[count..]) or { break }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
h.free()
|
h.free()
|
||||||
|
|
|
@ -12,7 +12,9 @@ fn (mut s StringReader) read(mut buf []byte) ?int {
|
||||||
if s.place >= s.text.len {
|
if s.place >= s.text.len {
|
||||||
return none
|
return none
|
||||||
}
|
}
|
||||||
n := copy(buf, s.text[s.place..].bytes())
|
max_bytes := 100
|
||||||
|
end := if s.place + max_bytes >= s.text.len { s.text.len } else { s.place + max_bytes }
|
||||||
|
n := copy(buf, s.text[s.place..end].bytes())
|
||||||
s.place += n
|
s.place += n
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
@ -135,3 +137,11 @@ ${contents[1]}
|
||||||
names[1]: contents[1] + '\n'
|
names[1]: contents[1] + '\n'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_parse_large_body() ? {
|
||||||
|
body := 'A'.repeat(101) // greater than max_bytes
|
||||||
|
req := 'GET / HTTP/1.1\r\nContent-Length: $body.len\r\n\r\n$body'
|
||||||
|
result := parse_request(mut reader(req)) ?
|
||||||
|
assert result.data.len == body.len
|
||||||
|
assert result.data == body
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue