Skip to content

Commit 2d4a601

Browse files
authored
webserver: string optimization (#7446)
* webserver: string optimization * fix
1 parent 83158af commit 2d4a601

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h

+10-8
Original file line numberDiff line numberDiff line change
@@ -95,29 +95,31 @@ class StaticRequestHandler : public RequestHandler<ServerType> {
9595
return true;
9696
}
9797

98-
bool handle(WebServerType& server, HTTPMethod requestMethod, const String& __requestUri) override {
99-
String requestUri(__requestUri);
98+
bool handle(WebServerType& server, HTTPMethod requestMethod, const String& requestUri) override {
10099

101100
if (!canHandle(requestMethod, requestUri))
102101
return false;
103102

104103
DEBUGV("StaticRequestHandler::handle: request=%s _uri=%s\r\n", requestUri.c_str(), _uri.c_str());
105104

106-
String path(_path);
105+
String path;
106+
path.reserve(_path.length() + requestUri.length() + 32);
107+
path = _path;
107108

108109
if (!_isFile) {
109-
// Base URI doesn't point to a file.
110-
// If a directory is requested, look for index file.
111-
if (requestUri.endsWith("/"))
112-
requestUri += "index.htm";
113110

114111
// Append whatever follows this URI in request to get the file path.
115112
path += requestUri.substring(_baseUriLength);
116113

114+
// Base URI doesn't point to a file.
115+
// If a directory is requested, look for index file.
116+
if (path.endsWith("/"))
117+
path += F("index.htm");
118+
117119
// If neither <blah> nor <blah>.gz exist, and <blah> is a file.htm, try it with file.html instead
118120
// For the normal case this will give a search order of index.htm, index.htm.gz, index.html, index.html.gz
119121
if (!_fs.exists(path) && !_fs.exists(path + ".gz") && path.endsWith(".htm")) {
120-
path += "l";
122+
path += 'l';
121123
}
122124
}
123125
DEBUGV("StaticRequestHandler::handle: path=%s, isFile=%d\r\n", path.c_str(), _isFile);

0 commit comments

Comments
 (0)