title: How does TCPStream know when a message is complete?
body: <p>In my understanding, <code>TCPStream</code> doesn't know when a complete message arrived from a client but the information arrives at a stream of bytes.</p>
  <p>However, when I do the standard &quot;Hello World&quot; <code>TCPStream</code> example in Rust, I am reading complete HTTP messages off the stream. When I send two or more messages, they will get separated accordingly.</p>
  <p>How is this possible?</p>
  <pre><code>use std::io::prelude::*;
  use std::net::TcpListener;
  use std::net::TcpStream;
  
  fn main() {
      let listener = TcpListener::bind(&quot;127.0.0.1:8080&quot;).unwrap();
  
      for stream in listener.incoming() {
          let stream = stream.unwrap();
          handle_connection(stream);
      }
  }
  
  fn handle_connection(mut stream: TcpStream) {
      let mut buffer = [0; 512];
      stream.read(&amp;mut buffer).unwrap();
      println!(&quot;{}&quot;, String::from_utf8_lossy(&amp;buffer[..]));
  }
  </code></pre>
  <p>When I reduce the buffer size, the HTTP messages are getting cut and newer messages start from the beginning. I would somehow assume that I have to manage ending and starting a new HTTP message myself?</p>