diff --git a/.gitignore b/.gitignore deleted file mode 100644 index df30947..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ - -.idea/ diff --git a/src/WebHandlers.cpp b/src/WebHandlers.cpp index db21df3..e7ee62f 100644 --- a/src/WebHandlers.cpp +++ b/src/WebHandlers.cpp @@ -28,16 +28,14 @@ AsyncStaticWebHandler::AsyncStaticWebHandler(FS& fs, const char* path, const cha if (_uri.length() == 0 || _uri[0] != '/') _uri = "/" + _uri; if (_path.length() == 0 || _path[0] != '/') _path = "/" + _path; - // If uri and path ends with '/' we assume a hint that this is a directory to improve performance. - // However - if one do not end '/' we, can't assume they are files, they can still be directory. - _isDir = _uri[_uri.length()-1] == '/' && _path[_path.length()-1] == '/'; + // If path ends with '/' we assume a hint that this is a directory to improve performance. + // However - if it does not end with '/' we, can't assume a file, path can still be a directory. + _isDir = _path[_path.length()-1] == '/'; - // If we serving directory - remove the trailing '/' so we can handle default file + // Remove the trailing '/' so we can handle default file // Notice that root will be "" not "/" - if (_isDir) { - _uri = _uri.substring(0, _uri.length()-1); - _path = _path.substring(0, _path.length()-1); - } + if (_uri[_uri.length()-1] == '/') _uri = _uri.substring(0, _uri.length()-1); + if (_path[_path.length()-1] == '/') _path = _path.substring(0, _path.length()-1); // Reset stats _gzipFirst = false; @@ -63,8 +61,8 @@ bool AsyncStaticWebHandler::_getFile(AsyncWebServerRequest *request) // Remove the found uri String path = request->url().substring(_uri.length()); - // We can skip the file check if we serving a directory and (we have full match or we end with '/') - bool canSkipFileCheck = _isDir && (path.length() == 0 || path[path.length()-1] == '/'); + // We can skip the file check and look for default if request is to the root of a directory or that request path ends with '/' + bool canSkipFileCheck = (_isDir && path.length() == 0) || (path.length() && path[path.length()-1] == '/'); path = _path + path; diff --git a/src/WebResponses.cpp b/src/WebResponses.cpp index 6534b6e..c74d0f9 100644 --- a/src/WebResponses.cpp +++ b/src/WebResponses.cpp @@ -357,7 +357,7 @@ void AsyncFileResponse::_setContentType(String path){ AsyncFileResponse::AsyncFileResponse(FS &fs, String path, String contentType, bool download){ _code = 200; _path = path; - + if(!download && !fs.exists(_path) && fs.exists(_path+".gz")){ _path = _path+".gz"; addHeader("Content-Encoding", "gzip");