1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-09-11 05:52:31 +03:00

Make getContentType available for 3rd party usage (#7254)

* Refactored to make getContentType public for 3rd party use.

* Added missing "jpeg" extension

* Use getContentType() from mime namespace.

* Also add .jpeg extension
This commit is contained in:
vdeconinck
2020-04-30 05:36:42 +02:00
committed by GitHub
parent 668b33ddf1
commit a9cf12fcf0
4 changed files with 26 additions and 59 deletions

View File

@@ -120,7 +120,7 @@ public:
}
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 @@ public:
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: