forked from espressif/arduino-esp32
Added overload on send to cleanly handle char arrays (#6721)
This commit is contained in:
@ -430,12 +430,32 @@ void WebServer::send(int code, const char* content_type, const String& content)
|
|||||||
// Can we asume the following?
|
// Can we asume the following?
|
||||||
//if(code == 200 && content.length() == 0 && _contentLength == CONTENT_LENGTH_NOT_SET)
|
//if(code == 200 && content.length() == 0 && _contentLength == CONTENT_LENGTH_NOT_SET)
|
||||||
// _contentLength = CONTENT_LENGTH_UNKNOWN;
|
// _contentLength = CONTENT_LENGTH_UNKNOWN;
|
||||||
|
if (content.length() == 0) {
|
||||||
|
log_w("content length is zero");
|
||||||
|
}
|
||||||
_prepareHeader(header, code, content_type, content.length());
|
_prepareHeader(header, code, content_type, content.length());
|
||||||
_currentClientWrite(header.c_str(), header.length());
|
_currentClientWrite(header.c_str(), header.length());
|
||||||
if(content.length())
|
if(content.length())
|
||||||
sendContent(content);
|
sendContent(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebServer::send(int code, char* content_type, const String& content) {
|
||||||
|
send(code, (const char*)content_type, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebServer::send(int code, const String& content_type, const String& content) {
|
||||||
|
send(code, (const char*)content_type.c_str(), content);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebServer::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);
|
||||||
|
}
|
||||||
|
|
||||||
void WebServer::send_P(int code, PGM_P content_type, PGM_P content) {
|
void WebServer::send_P(int code, PGM_P content_type, PGM_P content) {
|
||||||
size_t contentLength = 0;
|
size_t contentLength = 0;
|
||||||
|
|
||||||
@ -460,14 +480,6 @@ void WebServer::send_P(int code, PGM_P content_type, PGM_P content, size_t conte
|
|||||||
sendContent_P(content, contentLength);
|
sendContent_P(content, contentLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebServer::send(int code, char* content_type, const String& content) {
|
|
||||||
send(code, (const char*)content_type, content);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebServer::send(int code, const String& content_type, const String& content) {
|
|
||||||
send(code, (const char*)content_type.c_str(), content);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebServer::sendContent(const String& content) {
|
void WebServer::sendContent(const String& content) {
|
||||||
sendContent(content.c_str(), content.length());
|
sendContent(content.c_str(), content.length());
|
||||||
}
|
}
|
||||||
|
@ -120,6 +120,8 @@ public:
|
|||||||
void send(int code, const char* content_type = NULL, const String& content = String(""));
|
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, char* content_type, const String& content);
|
||||||
void send(int code, const String& content_type, const String& content);
|
void send(int code, const String& content_type, const String& content);
|
||||||
|
void send(int code, const char* content_type, const char* 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);
|
||||||
void send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength);
|
void send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user