diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp b/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp index 2aac608083..7d48e3769b 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp @@ -407,6 +407,14 @@ void ESP8266WebServer::send(int code, const char* content_type, const String& co sendContent(content); } +void ESP8266WebServer::send(int code, const char* content_type, const char* content, size_t contentLength) { + String header; + _prepareHeader(header, code, content_type, contentLength); + sendContent(header); + + sendContent(content, contentLength); +} + void ESP8266WebServer::send_P(int code, PGM_P content_type, PGM_P content) { size_t contentLength = 0; @@ -458,6 +466,20 @@ void ESP8266WebServer::sendContent(const String& content) { } } +void ESP8266WebServer::sendContent(const char* content, size_t contentLength) { + const size_t unit_size = HTTP_DOWNLOAD_UNIT_SIZE; + + while (contentLength) { + size_t will_send = (contentLength < unit_size) ? contentLength : unit_size; + size_t sent = _currentClient.write(content, will_send); + if (sent == 0) { + break; + } + contentLength -= sent; + content += sent; + } +} + void ESP8266WebServer::sendContent_P(PGM_P content) { sendContent_P(content, strlen_P(content)); } diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer.h b/libraries/ESP8266WebServer/src/ESP8266WebServer.h index 10e9a5666f..49f28e3c73 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer.h +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer.h @@ -117,6 +117,7 @@ class ESP8266WebServer // content - actual content body void send(int code, const char* content_type = NULL, const String& content = String("")); void send(int code, char* content_type, const String& content); + void send(int code, const char* content_type, const char* content, size_t contentLength); void send(int code, const String& content_type, const String& content); void send_P(int code, PGM_P content_type, PGM_P content); void send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength); @@ -124,6 +125,7 @@ class ESP8266WebServer void setContentLength(const size_t contentLength); void sendHeader(const String& name, const String& value, bool first = false); void sendContent(const String& content); + void sendContent(const char* content, size_t contentLength); void sendContent_P(PGM_P content); void sendContent_P(PGM_P content, size_t size);