WiFi WebServer for ESP8266
Fork of ESP8266_WebServer by
Diff: ESP8266_WebServer.cpp
- Revision:
- 4:759de84e790b
- Parent:
- 3:4ef7db7a95a7
- Child:
- 6:34d93ea4d519
diff -r 4ef7db7a95a7 -r 759de84e790b ESP8266_WebServer.cpp --- a/ESP8266_WebServer.cpp Thu Jan 01 16:27:58 2015 +0000 +++ b/ESP8266_WebServer.cpp Sat Jan 03 17:36:41 2015 +0000 @@ -239,6 +239,30 @@ } } +int ESP8266_WebServer::SendStream(int linkID, char const* reply, int StreamSize, int WindowSize, const char* mimeType, int maxAge) { + sprintf(response, "HTTP/1.1 200 OK\r\nContent-Type:%s\r\nContent-Length: %d\r\nCache-Control:max-age=%d\r\n\r\n", mimeType, StreamSize, maxAge); + sendResponse(linkID, strlen(response)); + return SendStream(linkID, reply, WindowSize); +} + +int ESP8266_WebServer::SendStream(int linkID, char const* reply, int WindowSize) { + char const* sendPtr = reply; + int bytesSent = 0; + while( bytesSent < WindowSize ) { + int bytesToSend = WindowSize - bytesSent; + if( bytesToSend > sizeof(response) ) { + bytesToSend = sizeof(response); + } + + memcpy(response, sendPtr, bytesToSend); + sendResponse(linkID, bytesToSend); + sendPtr += bytesToSend; + bytesSent += bytesToSend; + } + + return bytesSent; +} + ESP8266_WebRequest::ESP8266_WebRequest(const char* packet, Serial* debug) { int sz = strlen(packet); data = (char *)malloc(sz+1);