Extend built-in extension MIME mapping (#799)

* Update README.md

* Update httplib.h

* Update httplib.h

* Update httplib.h

* Update httplib.h

* Remove duplicate cases

Someone left a bunch of duplicate cases, idiot, couldn't have been me.

* Reformat

Modify spacing and whatnot

* Update README.md
This commit is contained in:
Anonymous 2020-12-18 06:32:19 -08:00 committed by GitHub
parent 0e3925db3f
commit 0cff3245df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 96 additions and 39 deletions

View File

@ -120,22 +120,48 @@ svr.set_file_extension_and_mimetype_mapping("hh", "text/x-h");
The followings are built-in mappings: The followings are built-in mappings:
| Extension | MIME Type | | Extension | MIME Type |
| :-------- | :--------------------- | | :--------- | :-------------------------- |
| txt | text/plain | | css | text/css |
| html, htm | text/html | | csv | text/csv |
| css | text/css | | txt | text/plain |
| jpeg, jpg | image/jpg | | vtt | text/vtt |
| png | image/png | | html, htm | text/html |
| gif | image/gif | | apng | image/apng |
| svg | image/svg+xml | | avif | image/avif |
| ico | image/x-icon | | bmp | image/bmp |
| json | application/json | | gif | image/gif |
| pdf | application/pdf | | png | image/png |
| js | application/javascript | | svg | image/svg+xml |
| wasm | application/wasm | | webp | image/webp |
| xml | application/xml | | ico | image/x-icon |
| xhtml | application/xhtml+xml | | tif | image/tiff |
| tiff | image/tiff |
| jpeg, jpg | image/jpeg |
| mp4 | video/mp4 |
| mpeg | video/mpeg |
| webm | video/webm |
| mp3 | audio/mp3 |
| mpga | audio/mpeg |
| weba | audio/webm |
| wav | audio/wave |
| otf | font/otf |
| ttf | font/ttf |
| woff | font/woff |
| woff2 | font/woff2 |
| 7z | application/x-7z-compressed |
| atom | application/atom+xml |
| pdf | application/pdf |
| mjs, js | application/javascript |
| json | application/json |
| rss | application/rss+xml |
| tar | application/x-tar |
| xhtml, xht | application/xhtml+xml |
| xslt | application/xslt+xml |
| xml | application/xml |
| gz | application/gzip |
| zip | application/zip |
| wasm | application/wasm |
NOTE: These the static file server methods are not thread safe. NOTE: These the static file server methods are not thread safe.

View File

@ -2148,9 +2148,9 @@ inline unsigned int str2tag(const std::string &s) {
namespace udl { namespace udl {
inline constexpr unsigned int operator"" _(const char *s, size_t l) { inline constexpr unsigned int operator"" _(const char *s, size_t l) {
return str2tag_core(s, l, 0); return str2tag_core(s, l, 0);
} }
} // namespace udl } // namespace udl
@ -2162,28 +2162,59 @@ find_content_type(const std::string &path,
auto it = user_data.find(ext); auto it = user_data.find(ext);
if (it != user_data.end()) { return it->second.c_str(); } if (it != user_data.end()) { return it->second.c_str(); }
using namespace udl; using udl::operator""_;
switch (str2tag(ext)) { switch (str2tag(ext)) {
case "txt"_: return "text/plain"; default: return nullptr;
case "html"_: case "css"_: return "text/css";
case "htm"_: return "text/html"; case "csv"_: return "text/csv";
case "css"_: return "text/css"; case "txt"_: return "text/plain";
case "jpeg"_: case "vtt"_: return "text/vtt";
case "jpg"_: return "image/jpg"; case "htm"_:
case "vtt"_: return "text/vtt"; case "html"_: return "text/html";
case "png"_: return "image/png";
case "gif"_: return "image/gif"; case "apng"_: return "image/apng";
case "svg"_: return "image/svg+xml"; case "avif"_: return "image/avif";
case "ico"_: return "image/x-icon"; case "bmp"_: return "image/bmp";
case "json"_: return "application/json"; case "gif"_: return "image/gif";
case "pdf"_: return "application/pdf"; case "png"_: return "image/png";
case "js"_: return "application/javascript"; case "svg"_: return "image/svg+xml";
case "wasm"_: return "application/wasm"; case "webp"_: return "image/webp";
case "xml"_: return "application/xml"; case "ico"_: return "image/x-icon";
case "xhtml"_: return "application/xhtml+xml"; case "tif"_: return "image/tiff";
case "mp4"_: return "video/mp4"; case "tiff"_: return "image/tiff";
default: return nullptr; case "jpg"_:
case "jpeg"_: return "image/jpeg";
case "mp4"_: return "video/mp4";
case "mpeg"_: return "video/mpeg";
case "webm"_: return "video/webm";
case "mp3"_: return "audio/mp3";
case "mpga"_: return "audio/mpeg";
case "weba"_: return "audio/webm";
case "wav"_: return "audio/wave";
case "otf"_: return "font/otf";
case "ttf"_: return "font/ttf";
case "woff"_: return "font/woff";
case "woff2"_: return "font/woff2";
case "7z"_: return "application/x-7z-compressed";
case "atom"_: return "application/atom+xml";
case "pdf"_: return "application/pdf";
case "js"_:
case "mjs"_: return "application/javascript";
case "json"_: return "application/json";
case "rss"_: return "application/rss+xml";
case "tar"_: return "application/x-tar";
case "xht"_:
case "xhtml"_: return "application/xhtml+xml";
case "xslt"_: return "application/xslt+xml";
case "xml"_: return "application/xml";
case "gz"_: return "application/gzip";
case "zip"_: return "application/zip";
case "wasm"_: return "application/wasm";
} }
} }