aboutsummaryrefslogtreecommitdiff
path: root/mime.c
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-01-19 11:28:41 +0000
committerOmar Polo <op@omarpolo.com>2021-01-19 11:28:41 +0000
commit6119e13e8aa794988b3875614a0a2c3ce0f07e7b (patch)
tree40680a673d8721c7f515adc57a9d5e467ba41972 /mime.c
parentdf79b4c1d5c7dda510accf2d407e318b33bb936d (diff)
moving "default type" from global options to server options
Diffstat (limited to 'mime.c')
-rw-r--r--mime.c26
1 files changed, 8 insertions, 18 deletions
diff --git a/mime.c b/mime.c
index 35ff72e..f81a813 100644
--- a/mime.c
+++ b/mime.c
@@ -24,24 +24,11 @@ void
init_mime(void)
{
conf.mimes.len = 0;
- conf.mimes.cap = 2;
+ conf.mimes.cap = 16;
conf.mimes.t = calloc(conf.mimes.cap, sizeof(struct etm));
if (conf.mimes.t == NULL)
fatal("calloc: %s", strerror(errno));
-
- conf.mimes.def = strdup("application/octet-stream");
- if (conf.mimes.def == NULL)
- fatal("strdup: %s", strerror(errno));
-
-}
-
-void
-set_default_mime(const char *m)
-{
- free(conf.mimes.def);
- if ((conf.mimes.def = strdup(m)) == NULL)
- fatal("strdup: %s", strerror(errno));
}
/* register mime for the given extension */
@@ -102,17 +89,20 @@ path_ext(const char *path)
}
const char *
-mime(const char *path)
+mime(struct vhost *host, const char *path)
{
- const char *ext;
+ const char *def, *ext;
struct etm *t;
+ if ((def = host->default_mime) == NULL)
+ def = "application/octet-stream";
+
if ((ext = path_ext(path)) == NULL)
- return conf.mimes.def;
+ return def;
for (t = conf.mimes.t; t->mime != NULL; ++t)
if (!strcmp(ext, t->ext))
return t->mime;
- return conf.mimes.def;
+ return def;
}