Using io::Cursor with TcpStream

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]);
  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; }

Not really.

Okay, lemme adopt it

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.