mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vweb: read the entire request body from buffered reader (#9644)
This commit is contained in:
parent
e93a52a267
commit
67ec33218e
@ -36,7 +36,10 @@ fn parse_request(mut reader io.BufferedReader) ?http.Request {
|
||||
n := length.int()
|
||||
if n > 0 {
|
||||
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()
|
||||
|
@ -12,7 +12,9 @@ fn (mut s StringReader) read(mut buf []byte) ?int {
|
||||
if s.place >= s.text.len {
|
||||
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
|
||||
return n
|
||||
}
|
||||
@ -135,3 +137,11 @@ ${contents[1]}
|
||||
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
Block a user