fix serving url with no trailing /

This commit is contained in:
Andrew Melvin
2016-01-27 23:42:16 +02:00
parent 9c5d0edf76
commit c6b2fa0ad4
3 changed files with 9 additions and 6 deletions

View File

@@ -26,11 +26,11 @@ class AsyncStaticWebHandler: public AsyncWebHandler {
_isFile = _fs.exists(path) || _fs.exists((String(path)+".gz").c_str());
if (_uri != "/" && _uri.endsWith("/")) {
_uri = _uri.substring(0, _uri.length() - 1);
DEBUGF("[AsyncStaticWebHandler] _uri / removed");
DEBUGF("[AsyncStaticWebHandler] _uri / removed\n");
}
if (_path != "/" && _path.endsWith("/")) {
_path = _path.substring(0, _path.length() - 1);
DEBUGF("[AsyncStaticWebHandler] _path / removed");
DEBUGF("[AsyncStaticWebHandler] _path / removed\n");
}

View File

@@ -9,7 +9,7 @@
#include "StringArray.h"
#define DEBUGF(...) //os_printf(__VA_ARGS__)
#define DEBUGF(...) //Serial.printf(__VA_ARGS__)
class AsyncWebServer;

View File

@@ -30,10 +30,13 @@ void AsyncStaticWebHandler::handleRequest(AsyncWebServerRequest *request)
String baserequestUrl = request->url().substring(_uri.length()); // this is the request - stored _uri... /espman/
DEBUGF(" baserequestUrl = %s\n", baserequestUrl.c_str());
if (baserequestUrl.length()) {
path = _path + baserequestUrl;
DEBUGF(" baserequestUrl length > 0: path = path + baserequestUrl, path = %s\n", path.c_str());
if (!baserequestUrl.length()) {
baserequestUrl += "/";
}
path = _path + baserequestUrl;
DEBUGF(" path = path + baserequestUrl, path = %s\n", path.c_str());
if (path.endsWith("/")) {
DEBUGF(" 3 path ends with / : path = index.htm \n");
path += "index.htm";