// should be called only after setStatus, addHeader and addContent void MTD_FLASHMEM HTTPResponse::flush() { // status line m_httpHandler->getSocket()->writeFmt(FSTR("HTTP/1.1 %s\r\n"), m_status); // HTTPResponse headers addHeader(FSTR("Connection"), FSTR("close")); // user headers for (uint32_t i = 0; i != m_headers.getItemsCount(); ++i) { Fields::Item* item = m_headers[i]; m_httpHandler->getSocket()->writeFmt(FSTR("%s: %s\r\n"), APtr<char>(t_strdup(item->key)).get(), APtr<char>(t_strdup(item->value)).get()); } // content length header m_httpHandler->getSocket()->writeFmt(FSTR("%s: %d\r\n\r\n"), STR_Content_Length, m_content.getItemsCount()); // actual content if (m_content.getItemsCount() > 0) { CharChunksIterator iter = m_content.getIterator(); CharChunkBase* chunk = iter.getCurrentChunk(); while (chunk) { m_httpHandler->getSocket()->write((uint8_t const*)chunk->data, chunk->getItems()); chunk = iter.moveToNextChunk(); } m_content.clear(); } }
// should be called only after setStatus, addHeader and addContent void MTD_FLASHMEM HTTPResponse::flush() { // headers flushHeaders(m_content.getItemsCount()); // actual content if (m_content.getItemsCount() > 0) { CharChunksIterator iter = m_content.getIterator(); CharChunkBase *chunk = iter.getCurrentChunk(); while (chunk) { if (m_httpHandler->getSocket()->write((uint8_t const *)chunk->data, chunk->getItems()) < 0) break; chunk = iter.moveToNextChunk(); } m_content.clear(); } }