Let's imagine that we start an HTTP server and an HTTP request to this server at the same time. It can happen that the first request will successfully connect to the remote server and write data to a stream (headers, body) but will be unable to reading response data (
stream.read() will always be 0 even if we retry it). This all works when the HTTP server is started
before the request is executed. Note that I'm starting my HTTP server using Docker.
Here's a snippet:
let mut stream = TcpStream::connect(&addr).await?; // CONNECT stream.write(b"GET /foo HTTP/1.1.\r\n").await?; // WRITE stream.write... ... let mut buff = vec![0u8; 1024]; let len = stream.read(&mut buff).await?; // READ => 0 when server is not ready
How should an HTTP client know when the HTTP server is ready to receive/write data (and retry when the server is not ready yet). I don't want to do an additional request (e.g.
HEAD /ready) just to see if I can write data to a stream (so the server will actually receive my messages). Also, I'm pretty positive that this issue is not related just to Rust and you should get the same effect using any other programing language. Any suggestions?