void MTD_FLASHMEM HTTPHandler::connectionHandler() {
  getSocket()->setTimeOut(TIMEOUT);
  while (getSocket()->isConnected()) {
    CharChunkBase *chunk = m_receivedData.addChunk(CHUNK_CAPACITY);
    int32_t bytesRecv = getSocket()->read(chunk->data, CHUNK_CAPACITY);
    if (bytesRecv <= 0)
      break;
    chunk->setItems(bytesRecv);
    if (processRequest())
      break;
  }
  m_receivedData.clear();
  m_request.query.clear();
  m_request.headers.clear();
  m_request.form.clear();
}
void MTD_FLASHMEM HTTPHandler::processXWWWFormUrlEncoded(CharChunksIterator headerEnd, int32_t contentLength) {
  // look for data (maybe POST data)
  if (contentLength > 0) {
    // download additional content
    int32_t missingBytes = headerEnd.getPosition() + contentLength - m_receivedData.getItemsCount();
    while (getSocket()->isConnected() && missingBytes > 0) {
      int32_t bytesToRead = (CHUNK_CAPACITY < missingBytes ? CHUNK_CAPACITY : missingBytes);
      CharChunkBase *chunk = m_receivedData.addChunk(bytesToRead);
      int32_t bytesRecv = getSocket()->read(chunk->data, bytesToRead);
      if (bytesRecv <= 0)
        break;
      chunk->setItems(bytesRecv);
      missingBytes -= chunk->getItems();
    }
    m_receivedData.append(0); // add additional terminating "0"

    CharChunksIterator contentStart = m_receivedData.getIterator(); // cannot use directly headerEnd because added data
    contentStart += headerEnd.getPosition();
    extractURLEncodedFields(contentStart, CharChunksIterator(), &m_request.form);
  }

  dispatch();
}