WiFi WebServer for ESP8266

Fork of ESP8266_WebServer by Sebastian Schocke

Revision:
2:6079554681d6
Parent:
1:1c4333ce7448
Child:
3:4ef7db7a95a7
--- a/ESP8266_WebServer.cpp	Thu Jan 01 10:22:31 2015 +0000
+++ b/ESP8266_WebServer.cpp	Thu Jan 01 14:59:13 2015 +0000
@@ -202,11 +202,22 @@
     SendReply(linkID, reply.c_str(), reply.length(), mimeType);
 }
 
-void ESP8266_WebServer::SendReply(int linkID, const char* reply, int replySize, const char* mimeType) {
+void ESP8266_WebServer::SendReply(int linkID, char const* reply, int replySize, const char* mimeType) {
     sprintf(response, "HTTP/1.1 200 OK\r\nContent-Type:%s\r\nContent-Length: %d\r\n\r\n", mimeType, replySize);
     sendResponse(linkID, strlen(response));
-    memcpy(response, reply, replySize);
-    sendResponse(linkID, replySize);
+    char const* sendPtr = reply;
+    int bytesSent = 0;
+    while( bytesSent < replySize ) {
+        int bytesToSend = replySize - bytesSent;
+        if( bytesToSend > sizeof(response) ) {
+            bytesToSend = sizeof(response);
+        }
+        
+        memcpy(response, sendPtr, bytesToSend);
+        sendResponse(linkID, bytesToSend);
+        sendPtr += bytesToSend;
+        bytesSent += bytesToSend;
+    }
 }
 
 void ESP8266_WebServer::SendFile(int linkID, FileHandle* file, const char* mimeType) {