forked from me-no-dev/ESPAsyncWebServer
Bug fix (#45)
* 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");
This commit is contained in:
@@ -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;
|
||||
|
@@ -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){
|
||||
|
Reference in New Issue
Block a user