From 89b19e8cde6a2261943fc0c1d3d167765a3d8c70 Mon Sep 17 00:00:00 2001 From: Hagai Shatz Date: Fri, 17 Jun 2016 22:32:09 +0100 Subject: [PATCH] Bug fix (#45) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * HTTP 302 and 304 Support Add support for http redirection (302) and http not modified (304) to reduce the load the server. server.redirect(“url”, “location”, exclude-ip) will respond with 302 to redirect the browser to a different url, this is useful for backward compatibility and to redirect call to CDN when not no AP mode. server.serveStatic has a new optional parameter to get the Last-Modified date for all files serve for this location, when the browser request have the same If-Modified-Since header value, the server respond with 304 code instead of serving the file. * First round of performance improvements. * Merge remote-tracking branch 'me-no-dev/master' into performance # Conflicts: # src/WebHandlerImpl.h # src/WebHandlers.cpp * use of sprintf * Remove sections not related. * Fix a bug to serve a file in directory (e.g. serverStatic("/", SPIFFS, "/index.html"); --- src/WebHandlers.cpp | 14 +++++++------- src/WebRequest.cpp | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/WebHandlers.cpp b/src/WebHandlers.cpp index 94483ae..db21df3 100644 --- a/src/WebHandlers.cpp +++ b/src/WebHandlers.cpp @@ -28,16 +28,16 @@ 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 or path ends with '/' we assume a hint that this is a directory to improve performance. - // However - if they both do not end '/' we, can't assume they are files, they can still be directory. - bool isUriDir = _uri[_uri.length()-1] == '/'; - bool isPathDir = _path[_path.length()-1] == '/'; - _isDir = isUriDir || isPathDir; + // 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 we serving directory - remove the trailing '/' so we can handle default file // Notice that root will be "" not "/" - if (_isDir && isUriDir) _uri = _uri.substring(0, _uri.length()-1); - if (_isDir && isPathDir) _path = _path.substring(0, _path.length()-1); + if (_isDir) { + _uri = _uri.substring(0, _uri.length()-1); + _path = _path.substring(0, _path.length()-1); + } // Reset stats _gzipFirst = false; diff --git a/src/WebRequest.cpp b/src/WebRequest.cpp index 617f8f1..238f5b6 100644 --- a/src/WebRequest.cpp +++ b/src/WebRequest.cpp @@ -117,7 +117,7 @@ void AsyncWebServerRequest::_onData(void *buf, size_t len){ _temp.concat(str); _temp.trim(); _parseLine(); - if (++i < len) _onData(buf+i, len-i); // Still have more buffer to process + if (++i < len) _onData(str+i, len-i); // Still have more buffer to process } } else if(_parseState == PARSE_REQ_BODY){ if(_isMultipart){