summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/Http.h2
-rw-r--r--src/Http.cc18
2 files changed, 20 insertions, 0 deletions
diff --git a/includes/Http.h b/includes/Http.h
index fae2ad9..00db23a 100644
--- a/includes/Http.h
+++ b/includes/Http.h
@@ -16,6 +16,8 @@ namespace Http {
const char * getStatusMsg(int httpStatus);
+const char * getContentType(const String & extension);
+
typedef std::map<String, String> StringMap;
typedef std::map<String, IO<Handle> > FileList;
diff --git a/src/Http.cc b/src/Http.cc
index 4e3e2a6..4ae240e 100644
--- a/src/Http.cc
+++ b/src/Http.cc
@@ -1,3 +1,5 @@
+#include <map>
+
#include "Http.h"
const char * Balau::Http::getStatusMsg(int httpStatus) {
@@ -46,3 +48,19 @@ const char * Balau::Http::getStatusMsg(int httpStatus) {
}
return "Unknown HTTP code";
}
+
+static std::map<Balau::String, const char *> s_mimeMap {
+ std::make_pair("css", "text/css"),
+ std::make_pair("html", "text/html"),
+ std::make_pair("js", "application/javascript"),
+ std::make_pair("json", "application/json"),
+ std::make_pair("png", "image/png"),
+ std::make_pair("gif", "image/gif"),
+};
+
+const char * Balau::Http::getContentType(const String & extension) {
+ auto t = s_mimeMap.find(extension);
+ if (t == s_mimeMap.end())
+ return "application/octet-stream";
+ return t->second;
+}