diff options
| author | Drew DeVault <sir@cmpwn.com> | 2020-09-26 14:36:52 -0400 |
|---|---|---|
| committer | Drew DeVault <sir@cmpwn.com> | 2020-09-26 14:36:52 -0400 |
| commit | dfab99ace5f1193ca6df0ed7b704ea450a2fae95 (patch) | |
| tree | 19bac79e0fdadccfcd028666685e77febefb11c3 /src/mime.c | |
| parent | 0d6eca2c7922a14f1b9d0b46cf42816c6097743a (diff) | |
| download | gmnisrv-dfab99ace5f1193ca6df0ed7b704ea450a2fae95.tar.gz gmnisrv-dfab99ace5f1193ca6df0ed7b704ea450a2fae95.tar.xz gmnisrv-dfab99ace5f1193ca6df0ed7b704ea450a2fae95.zip | |
Serve files from root
Diffstat (limited to 'src/mime.c')
| -rw-r--r-- | src/mime.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/mime.c b/src/mime.c new file mode 100644 index 0000000..5722357 --- /dev/null +++ b/src/mime.c @@ -0,0 +1,30 @@ +#include <stdbool.h> +#include <string.h> +#include "mime.h" + +static bool +has_suffix(const char *str, const char *suff) +{ + size_t a = strlen(str), b = strlen(suff); + if (a < b) { + return false; + } + return strncmp(&str[a - b], suff, b) == 0; +} + +const char * +gmnisrv_mimetype_for_path(const char *path) +{ + // TODO: Read /etc/mime.types + // TODO: Consider adding content-disposition fields like filename + if (has_suffix(path, ".gmi") || has_suffix(path, ".gemini")) { + return "text/gemini"; + } + if (has_suffix(path, ".txt")) { + return "text/plain"; + } + if (has_suffix(path, ".png")) { + return "image/png"; + } + return "application/octet-stream"; +} |
