add some mime types and a commented implementation of etag for cache

This commit is contained in:
Me No Dev 2016-08-25 22:15:17 +03:00
parent a14e93dd84
commit 1163808495
2 changed files with 19 additions and 1 deletions

View File

@ -89,6 +89,9 @@ bool AsyncStaticWebHandler::canHandle(AsyncWebServerRequest *request)
if (_last_modified.length())
request->addInterestingHeader("If-Modified-Since");
//if(_cache_control.length())
// request->addInterestingHeader("If-None-Match");
DEBUGF("[AsyncStaticWebHandler::canHandle] TRUE\n");
return true;
}
@ -180,14 +183,24 @@ void AsyncStaticWebHandler::handleRequest(AsyncWebServerRequest *request)
request->_tempObject = NULL;
if (request->_tempFile == true) {
//String etag = String(request->_tempFile.size());
if (_last_modified.length() && _last_modified == request->header("If-Modified-Since")) {
request->_tempFile.close();
request->send(304); // Not modified
/*} else if (_cache_control.length() && request->hasHeader("If-None-Match") && request->header("If-None-Match").equals(etag)) {
request->_tempFile.close();
AsyncWebServerResponse * response = new AsyncBasicResponse(304); // Not modified
response->addHeader("Cache-Control", _cache_control);
response->addHeader("ETag", etag);
request->send(response);*/
} else {
AsyncWebServerResponse * response = new AsyncFileResponse(request->_tempFile, filename);
if (_last_modified.length())
response->addHeader("Last-Modified", _last_modified);
if (_cache_control.length())
if (_cache_control.length()){
response->addHeader("Cache-Control", _cache_control);
//response->addHeader("ETag", etag);
}
request->send(response);
}
} else {

View File

@ -347,12 +347,17 @@ void AsyncFileResponse::_setContentType(String path){
if (path.endsWith(".html")) _contentType = "text/html";
else if (path.endsWith(".htm")) _contentType = "text/html";
else if (path.endsWith(".css")) _contentType = "text/css";
else if (path.endsWith(".json")) _contentType = "text/json";
else if (path.endsWith(".js")) _contentType = "application/javascript";
else if (path.endsWith(".png")) _contentType = "image/png";
else if (path.endsWith(".gif")) _contentType = "image/gif";
else if (path.endsWith(".jpg")) _contentType = "image/jpeg";
else if (path.endsWith(".ico")) _contentType = "image/x-icon";
else if (path.endsWith(".svg")) _contentType = "image/svg+xml";
else if (path.endsWith(".eot")) _contentType = "font/eot";
else if (path.endsWith(".woff")) _contentType = "font/woff";
else if (path.endsWith(".woff2")) _contentType = "font/woff2";
else if (path.endsWith(".ttf")) _contentType = "font/ttf";
else if (path.endsWith(".xml")) _contentType = "text/xml";
else if (path.endsWith(".pdf")) _contentType = "application/pdf";
else if (path.endsWith(".zip")) _contentType = "application/zip";