From 7ef44d9878f2a4e6d686c78da0cfe01938aad0bf Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Wed, 31 Aug 2022 08:21:16 -0700 Subject: [PATCH] Clean up WebServer send() methods (#820) Avoid creating Strings when sending out results. --- libraries/WebServer/src/HTTPServer.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/libraries/WebServer/src/HTTPServer.cpp b/libraries/WebServer/src/HTTPServer.cpp index a96b14d3..e1be1295 100644 --- a/libraries/WebServer/src/HTTPServer.cpp +++ b/libraries/WebServer/src/HTTPServer.cpp @@ -385,11 +385,7 @@ void HTTPServer::send(int code, const String& content_type, const String& conten } void HTTPServer::send(int code, const char* content_type, const char* content) { - const String passStr = (String)content; - if (strlen(content) != passStr.length()) { - log_e("String cast failed. Use send_P for long arrays"); - } - send(code, content_type, passStr); + send(code, content_type, content, content ? strlen(content) : 0); } void HTTPServer::send(int code, const char* content_type, const char* content, size_t contentLength) { @@ -409,18 +405,14 @@ void HTTPServer::send_P(int code, PGM_P content_type, PGM_P content) { } String header; - char type[64]; - memccpy_P((void*)type, (PGM_VOID_P)content_type, 0, sizeof(type)); - _prepareHeader(header, code, (const char*)type, contentLength); + _prepareHeader(header, code, content_type, contentLength); _currentClientWrite(header.c_str(), header.length()); sendContent_P(content); } void HTTPServer::send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength) { String header; - char type[64]; - memccpy_P((void*)type, (PGM_VOID_P)content_type, 0, sizeof(type)); - _prepareHeader(header, code, (const char*)type, contentLength); + _prepareHeader(header, code, content_type, contentLength); sendContent(header); sendContent_P(content, contentLength); }