diff --git a/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino b/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino index caf8634926..beebeb0146 100644 --- a/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino +++ b/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino @@ -115,49 +115,6 @@ void replyServerError(String msg) { server.send(500, FPSTR(TEXT_PLAIN), msg + "\r\n"); } -String getContentType(String filename) { - if (filename.endsWith(".htm")) { - return "text/html"; - } - if (filename.endsWith(".html")) { - return "text/html"; - } - if (filename.endsWith(".css")) { - return "text/css"; - } - if (filename.endsWith(".js")) { - return "application/javascript"; - } - if (filename.endsWith(".png")) { - return "image/png"; - } - if (filename.endsWith(".gif")) { - return "image/gif"; - } - if (filename.endsWith(".jpg")) { - return "image/jpeg"; - } - if (filename.endsWith(".jpeg")) { - return "image/jpeg"; - } - if (filename.endsWith(".ico")) { - return "image/x-icon"; - } - if (filename.endsWith(".xml")) { - return "text/xml"; - } - if (filename.endsWith(".pdf")) { - return "application/x-pdf"; - } - if (filename.endsWith(".zip")) { - return "application/x-zip"; - } - if (filename.endsWith(".gz")) { - return "application/x-gzip"; - } - return FPSTR(TEXT_PLAIN); -} - #ifdef USE_SPIFFS /* Checks filename for character combinations that are not supported by FSBrowser (alhtough valid on SPIFFS). @@ -304,7 +261,7 @@ bool handleFileRead(String path) { if (server.hasArg("download")) { contentType = F("application/octet-stream"); } else { - contentType = getContentType(path); + contentType = mime::getContentType(path); } if (!fileSystem->exists(path)) { diff --git a/libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h b/libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h index 9388d4ac43..fb452af48c 100644 --- a/libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h +++ b/libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h @@ -120,7 +120,7 @@ class StaticRequestHandler : public RequestHandler { } DEBUGV("StaticRequestHandler::handle: path=%s, isFile=%d\r\n", path.c_str(), _isFile); - String contentType = getContentType(path); + String contentType = mime::getContentType(path); // look for gz file, only if the original specified path is not a gz. So part only works to send gzip via content encoding when a non compressed is asked for // if you point the the path to gzip you will serve the gzip as content type "application/x-gzip", not text or javascript etc... @@ -146,19 +146,9 @@ class StaticRequestHandler : public RequestHandler { return true; } - static String getContentType(const String& path) { - char buff[sizeof(mimeTable[0].mimeType)]; - // Check all entries but last one for match, return if found - for (size_t i=0; i < sizeof(mimeTable)/sizeof(mimeTable[0])-1; i++) { - strcpy_P(buff, mimeTable[i].endsWith); - if (path.endsWith(buff)) { - strcpy_P(buff, mimeTable[i].mimeType); - return String(buff); - } - } - // Fall-through and just return default type - strcpy_P(buff, mimeTable[sizeof(mimeTable)/sizeof(mimeTable[0])-1].mimeType); - return String(buff); + /* Deprecated version. Please use mime::getContentType instead */ + static String getContentType(const String& path) __attribute__((deprecated)) { + return mime::getContentType(path); } protected: diff --git a/libraries/ESP8266WebServer/src/detail/mimetable.cpp b/libraries/ESP8266WebServer/src/detail/mimetable.cpp index d646857a8a..c4a20cc0e1 100644 --- a/libraries/ESP8266WebServer/src/detail/mimetable.cpp +++ b/libraries/ESP8266WebServer/src/detail/mimetable.cpp @@ -1,5 +1,6 @@ #include "mimetable.h" #include "pgmspace.h" +#include "WString.h" namespace mime { @@ -16,6 +17,7 @@ const Entry mimeTable[maxType] PROGMEM = { ".png", "image/png" }, { ".gif", "image/gif" }, { ".jpg", "image/jpeg" }, + { ".jpeg", "image/jpeg" }, { ".ico", "image/x-icon" }, { ".svg", "image/svg+xml" }, { ".ttf", "application/x-font-ttf" }, @@ -32,4 +34,19 @@ const Entry mimeTable[maxType] PROGMEM = { "", "application/octet-stream" } }; + String getContentType(const String& path) { + char buff[sizeof(mimeTable[0].mimeType)]; + // Check all entries but last one for match, return if found + for (size_t i=0; i < sizeof(mimeTable)/sizeof(mimeTable[0])-1; i++) { + strcpy_P(buff, mimeTable[i].endsWith); + if (path.endsWith(buff)) { + strcpy_P(buff, mimeTable[i].mimeType); + return String(buff); + } + } + // Fall-through and just return default type + strcpy_P(buff, mimeTable[sizeof(mimeTable)/sizeof(mimeTable[0])-1].mimeType); + return String(buff); + } + } diff --git a/libraries/ESP8266WebServer/src/detail/mimetable.h b/libraries/ESP8266WebServer/src/detail/mimetable.h index 191356c489..6e6a4e9631 100644 --- a/libraries/ESP8266WebServer/src/detail/mimetable.h +++ b/libraries/ESP8266WebServer/src/detail/mimetable.h @@ -1,6 +1,7 @@ #ifndef __MIMETABLE_H__ #define __MIMETABLE_H__ +#include "WString.h" namespace mime { @@ -16,6 +17,7 @@ enum type png, gif, jpg, + jpeg, ico, svg, ttf, @@ -41,7 +43,8 @@ struct Entry extern const Entry mimeTable[maxType]; -} +String getContentType(const String& path); +} #endif pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy