I've written this function to help me parse http requests. By now it's just returning length of the headers, an information I'll be using later. Does it have any downside?
fn parse_headers(stream: &TcpStream) -> usize {
let mut cursor = Cursor::new([0u8; 1024]);
stream.peek(cursor.get_mut()).unwrap();
let mut buff = Vec::new();
let mut size = 0usize;
loop {
let bytes = cursor.read_until(b'\n', &mut buff).unwrap();
println!("{:?}", String::from_utf8(buff.drain(0..).collect()).unwrap());
size += bytes;
if bytes < 3 { break; }
}
size
}