sirleech/Webduino

loss of data in function int WebServer::read()

Closed this issue · 1 comments

In function "int WebServer::read()", when reading the content (m_readingContent is true, m_contentLength is non-zero), if the http body from the client to the server is under transmission (The server has not received the http body yet), the read at line"int ch = m_client.read();" returns -1. In this case m_contentLength is decreased, but the data isn't read. This results in the loss of data.

To fix this issue, m_contentLength should be increased if no data returned. See the code below.

  int ch = m_client.read();
  ...
  if (ch != -1)
  {
    ...
  }
  else
  {
    m_contentLength++; //Jeffrey>> BUG FIX at Line 691. Increase the index if there is no data returned.

    unsigned long now = millis();
    ...
  }

Thanks for the bug report. I'm actually going to fix this by moving the decrement into the ch != -1 branch.