12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #ifndef _XS_MIME
- #define _XS_MIME
- char *xs_mime_by_ext(char *file);
- #ifdef XS_IMPLEMENTATION
- struct _mime_info {
- char *type;
- char *ext;
- } mime_info[] = {
- { "application/json", ".json" },
- { "image/gif", ".gif" },
- { "image/jpeg", ".jpeg" },
- { "image/jpeg", ".jpg" },
- { "image/png", ".png" },
- { "image/webp", ".webp" },
- { "text/css", ".css" },
- { "text/html", ".html" },
- { "text/plain", ".txt" },
- { "text/xml", ".xml" },
- { NULL, NULL }
- };
- char *xs_mime_by_ext(char *file)
- {
- struct _mime_info *mi = mime_info;
- char *p = NULL;
- while (p == NULL && mi->type != NULL) {
- if (xs_endswith(file, mi->ext))
- p = mi->type;
- mi++;
- }
- if (p == NULL)
- p = "application/octet-stream";
- return p;
- }
- #endif
- #endif
|