Skip to content

Commit f57c367

Browse files
authored
Add sendContent overload that takes a const char* and a length (#4276)
The web server currently lacks the ability to send a buffer. Only strings are supported. This PR adds an overload to sendContent.
1 parent 3054bdf commit f57c367

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Diff for: libraries/WebServer/src/WebServer.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -463,20 +463,23 @@ void WebServer::send(int code, const String& content_type, const String& content
463463
}
464464

465465
void WebServer::sendContent(const String& content) {
466+
sendContent(content.c_str(), content.length());
467+
}
468+
469+
void WebServer::sendContent(const char* content, size_t contentLength) {
466470
const char * footer = "\r\n";
467-
size_t len = content.length();
468471
if(_chunked) {
469472
char * chunkSize = (char *)malloc(11);
470473
if(chunkSize){
471-
sprintf(chunkSize, "%x%s", len, footer);
474+
sprintf(chunkSize, "%x%s", contentLength, footer);
472475
_currentClientWrite(chunkSize, strlen(chunkSize));
473476
free(chunkSize);
474477
}
475478
}
476-
_currentClientWrite(content.c_str(), len);
479+
_currentClientWrite(content, contentLength);
477480
if(_chunked){
478481
_currentClient.write(footer, 2);
479-
if (len == 0) {
482+
if (contentLength == 0) {
480483
_chunked = false;
481484
}
482485
}

Diff for: libraries/WebServer/src/WebServer.h

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class WebServer
130130
void setContentLength(const size_t contentLength);
131131
void sendHeader(const String& name, const String& value, bool first = false);
132132
void sendContent(const String& content);
133+
void sendContent(const char* content, size_t contentLength);
133134
void sendContent_P(PGM_P content);
134135
void sendContent_P(PGM_P content, size_t size);
135136

0 commit comments

Comments
 (0)