From 68574addd5dfc4e3af8c902b7cf4f3d946bc89b9 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Fri, 10 Jul 2020 16:09:44 +0200 Subject: [PATCH 1/2] webserver: string optimization --- .../src/detail/RequestHandlersImpl.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h b/libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h index 005a522a06..6ff995b2a1 100644 --- a/libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h +++ b/libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h @@ -95,29 +95,31 @@ class StaticRequestHandler : public RequestHandler { return true; } - bool handle(WebServerType& server, HTTPMethod requestMethod, const String& __requestUri) override { - String requestUri(__requestUri); + bool handle(WebServerType& server, HTTPMethod requestMethod, const String& requestUri) override { if (!canHandle(requestMethod, requestUri)) return false; DEBUGV("StaticRequestHandler::handle: request=%s _uri=%s\r\n", requestUri.c_str(), _uri.c_str()); - String path(_path); + String path; + path.reserve(_path.length() + requestUri().length() + 32); + path = _path; if (!_isFile) { - // Base URI doesn't point to a file. - // If a directory is requested, look for index file. - if (requestUri.endsWith("/")) - requestUri += "index.htm"; // Append whatever follows this URI in request to get the file path. path += requestUri.substring(_baseUriLength); + // Base URI doesn't point to a file. + // If a directory is requested, look for index file. + if (path.endsWith("/")) + path += F("index.htm"); + // If neither nor .gz exist, and is a file.htm, try it with file.html instead // For the normal case this will give a search order of index.htm, index.htm.gz, index.html, index.html.gz if (!_fs.exists(path) && !_fs.exists(path + ".gz") && path.endsWith(".htm")) { - path += "l"; + path += 'l'; } } DEBUGV("StaticRequestHandler::handle: path=%s, isFile=%d\r\n", path.c_str(), _isFile); From fd850478520f1b151469a86bbabe5d6e35269d0f Mon Sep 17 00:00:00 2001 From: david gauchard Date: Fri, 10 Jul 2020 16:38:34 +0200 Subject: [PATCH 2/2] fix --- libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h b/libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h index 6ff995b2a1..bb626abbd8 100644 --- a/libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h +++ b/libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h @@ -103,7 +103,7 @@ class StaticRequestHandler : public RequestHandler { DEBUGV("StaticRequestHandler::handle: request=%s _uri=%s\r\n", requestUri.c_str(), _uri.c_str()); String path; - path.reserve(_path.length() + requestUri().length() + 32); + path.reserve(_path.length() + requestUri.length() + 32); path = _path; if (!_isFile) {