Skip to content

Instantly share code, notes, and snippets.

@DefectingCat
Created January 30, 2024 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DefectingCat/995da71c8070e4d444ddb425b37afac3 to your computer and use it in GitHub Desktop.
Save DefectingCat/995da71c8070e4d444ddb425b37afac3 to your computer and use it in GitHub Desktop.
rust async read tcp stream as header to string
pub async fn read_headers<R>(reader: R) -> Result<String>
where
R: AsyncRead + std::marker::Unpin,
{
let mut request_string = String::new();
let mut reader = BufReader::new(reader);
loop {
let byte = reader.read_line(&mut request_string).await?;
if byte < 3 {
break;
}
}
Ok(request_string)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment