1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

ESP8266WebServer: reduce amount of string copying

This commit is contained in:
Ivan Grokhotkov 2015-06-24 23:58:53 +03:00
parent b029e78a67
commit e5fcdbd9e3
2 changed files with 11 additions and 11 deletions

View File

@ -115,7 +115,7 @@ void ESP8266WebServer::handleClient()
_handleRequest();
}
void ESP8266WebServer::sendHeader(String name, String value, bool first) {
void ESP8266WebServer::sendHeader(const String& name, const String& value, bool first) {
String headerLine = name;
headerLine += ": ";
headerLine += value;
@ -129,7 +129,7 @@ void ESP8266WebServer::sendHeader(String name, String value, bool first) {
}
}
void ESP8266WebServer::send(int code, const char* content_type, String content) {
void ESP8266WebServer::send(int code, const char* content_type, const String& content) {
String response = "HTTP/1.1 ";
response += String(code);
response += " ";
@ -155,15 +155,15 @@ void ESP8266WebServer::send(int code, const char* content_type, String content)
sendContent(response);
}
void ESP8266WebServer::send(int code, char* content_type, String content) {
void ESP8266WebServer::send(int code, char* content_type, const String& content) {
send(code, (const char*)content_type, content);
}
void ESP8266WebServer::send(int code, String content_type, String content) {
void ESP8266WebServer::send(int code, const String& content_type, const String& content) {
send(code, (const char*)content_type.c_str(), content);
}
void ESP8266WebServer::sendContent(String content) {
void ESP8266WebServer::sendContent(const String& content) {
size_t size_to_send = content.length();
size_t size_sent = 0;
while(size_to_send) {

View File

@ -77,15 +77,15 @@ public:
// code - HTTP response code, can be 200 or 404
// content_type - HTTP content type, like "text/plain" or "image/png"
// content - actual content body
void send(int code, const char* content_type = NULL, String content = String(""));
void send(int code, char* content_type, String content);
void send(int code, String content_type, String content);
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 String& content_type, const String& content);
void setContentLength(size_t contentLength) { _contentLength = contentLength; }
void sendHeader(String name, String value, bool first = false);
void sendContent(String content);
void sendHeader(const String& name, const String& value, bool first = false);
void sendContent(const String& content);
template<typename T> size_t streamFile(T &file, String contentType){
template<typename T> size_t streamFile(T &file, const String& contentType){
setContentLength(file.size());
if (String(file.name()).endsWith(".gz") &&
contentType != "application/x-gzip" &&