-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxs_mime.h
52 lines (38 loc) · 1.05 KB
/
xs_mime.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* copyright (c) 2022 grunfink - MIT license */
#ifndef _XS_MIME
#define _XS_MIME
char *xs_mime_by_ext(const char *file);
#ifdef XS_IMPLEMENTATION
/* intentionally brain-dead simple */
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(const char *file)
/* returns the MIME type by file extension */
{
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 /* XS_IMPLEMENTATION */
#endif /* XS_MIME */