diff --git a/libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h b/libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h index 005a522a06..bb626abbd8 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);