Skip to content

Commit e069193

Browse files
committed
Add sendContent overload that takes a const char* and a length
1 parent 4d98cea commit e069193

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

libraries/WebServer/src/WebServer.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,20 +454,23 @@ void WebServer::send(int code, const String& content_type, const String& content
454454
}
455455

456456
void WebServer::sendContent(const String& content) {
457+
sendContent(content.c_str(), content.length());
458+
}
459+
460+
void WebServer::sendContent(const char* content, size_t contentLength) {
457461
const char * footer = "\r\n";
458-
size_t len = content.length();
459462
if(_chunked) {
460463
char * chunkSize = (char *)malloc(11);
461464
if(chunkSize){
462-
sprintf(chunkSize, "%x%s", len, footer);
465+
sprintf(chunkSize, "%x%s", contentLength, footer);
463466
_currentClientWrite(chunkSize, strlen(chunkSize));
464467
free(chunkSize);
465468
}
466469
}
467-
_currentClientWrite(content.c_str(), len);
470+
_currentClientWrite(content, contentLength);
468471
if(_chunked){
469472
_currentClient.write(footer, 2);
470-
if (len == 0) {
473+
if (contentLength == 0) {
471474
_chunked = false;
472475
}
473476
}

libraries/WebServer/src/WebServer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class WebServer
129129
void setContentLength(const size_t contentLength);
130130
void sendHeader(const String& name, const String& value, bool first = false);
131131
void sendContent(const String& content);
132+
void sendContent(const char* content, size_t contentLength);
132133
void sendContent_P(PGM_P content);
133134
void sendContent_P(PGM_P content, size_t size);
134135

0 commit comments

Comments
 (0)