mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
webserver: string optimization (#7446)
* webserver: string optimization * fix
This commit is contained in:
parent
83158affa8
commit
2d4a601c18
@ -95,29 +95,31 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handle(WebServerType& server, HTTPMethod requestMethod, const String& __requestUri) override {
|
bool handle(WebServerType& server, HTTPMethod requestMethod, const String& requestUri) override {
|
||||||
String requestUri(__requestUri);
|
|
||||||
|
|
||||||
if (!canHandle(requestMethod, requestUri))
|
if (!canHandle(requestMethod, requestUri))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
DEBUGV("StaticRequestHandler::handle: request=%s _uri=%s\r\n", requestUri.c_str(), _uri.c_str());
|
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) {
|
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.
|
// Append whatever follows this URI in request to get the file path.
|
||||||
path += requestUri.substring(_baseUriLength);
|
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 <blah> nor <blah>.gz exist, and <blah> is a file.htm, try it with file.html instead
|
// If neither <blah> nor <blah>.gz exist, and <blah> 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
|
// 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")) {
|
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);
|
DEBUGV("StaticRequestHandler::handle: path=%s, isFile=%d\r\n", path.c_str(), _isFile);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user